配置虚拟主机之后访问站点。提示我没有权限访问权限
一般情况下有以下几个问题;
1,站点目录访问权限配置问题
2, 目录权限问题
3,路径问题
提示我没有权限,解决思路,第一步检查站点目录权限设置
[[email protected]_lamp html]#tree
.
├── bbs
│ └── index.html
├── blog
│ └── index.html
└── www
└── index.html
3 directories, 3 files
[[email protected]_lamp html]#ll
total 12
drwxrwxrwx 2 root root4096 Mar 4 07:57 bbs
drwxrwxrwx 2 root root4096 Mar 4 07:58 blog
drwxrwxrwx 2 root root4096 Mar 4 07:58 www
我给目录最大权限。 777 依然报错
第二步检查我的配置的站点目录权限
[[email protected]_lamp conf]#diff httpd.conf httpd.conf-2015-02
161,162c161,162
< User www
< Group www
---
> User daemon
> Group daemon
192c192
< ServerNamelocalhost:80
---
> #ServerNamewww.example.com:80
250c250
< DirectoryIndex index.php index.html
---
> DirectoryIndex index.html
275c275
< LogLevel error
---
> LogLevel warn
379,380d378
< AddType application/x-httpd-php .php
< AddType application/x-httpd-souce .phps
450c448
< Includeconf/extra/httpd-mpm.conf
---
> #Include conf/extra/httpd-mpm.conf
468c466
< Includeconf/extra/httpd-vhosts.conf
---
> #Includeconf/extra/httpd-vhosts.conf
507,513d504
<
< <Directory"/data0/html">
< Options FollowSymLinks
< AllowOverride None
< Order allow,deny
< Allow from all
< </Directory>
[[email protected]_lamp conf]#/etc/init.d/httpd graceful
访问
You don‘t havepermission to access / on this server. 网页显示403 禁止访问
查看解析
20.0.0.10 www.wangxing.org
20.0.0.10 bbs.wangxing.org
20.0.0.10 blog.wangxing.org
客户端解析
检查解析ok
防火墙:
[[email protected]_lamp conf]#/etc/init.d/iptables status
iptables: Firewall isnot running.
[[email protected]_lamp conf]#/etc/init.d/iptables stop
[[email protected]_lamp conf]#getenforce
Disabled
查看源码
403 错误
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET /favicon.ico HTTP/1.1" 403 220
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET / HTTP/1.1" 403 209
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET /favicon.ico HTTP/1.1" 403 220
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET / HTTP/1.1" 403 209
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET /favicon.ico HTTP/1.1" 403 220
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET / HTTP/1.1" 403 209
20.0.0.1 - -[04/Mar/2015:08:59:25 +0800] "GET /favicon.icoHTTP/1.1" 403 220
https://wiki.apache.org/httpd/ClientDeniedByServerConfiguration 查看官网修改内容
根据错误提示
Youdon‘t have permission to access / on this server. 去官网查找原因
http://httpd.apache.org/docs/2.4/upgrading.html 根据官网的资料修改权限之后ok
查看apache的配置文件,httpd.conf
<Directory />
AllowOverride none
Requireall denied
</Directory>
这句话的意思是拒绝我/ 目录的访问,这可能是apache 出于安全的考虑,只需要将这句话注释掉或者修改就可以解决问题,如何修改请参考官网的解释
http://httpd.apache.org/docs/2.4/upgrading.html ,但是很多情况下有些是默认的还是可以访问的,但是我的问题修改之后解决了,
总结,在配置虚拟主机和php设置的时候
1. Apache 整合php配置
Php的官网建议采用以下配置文件作为添加
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
将这句话添加到httpd.conf 最后面,
还有php的源码过滤器,但是官网不建议在生产环境中去使用,出于对安全的考虑
<FilesMatch "\.phps$">
SetHandlerapplication/x-httpd-php-source
</FilesMatch>
2,站点目录权限的配置
站点目录权限的配置可以添加在httpd.conf 中,也可以添加在httpd-vhosts.conf 文件中,
<Directory"/data0/html">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
可以添加在虚拟配置文件中,也可以添加在虚拟配置文件最后面,
可以使用/usr/local/apache2/bin/apachectl –S 去检查虚拟主机的配置文件
然后使用/usr/local/apache2/bin/apachectl graceful 去测试,
备注:apache 官网的帮助需要翻墙,呵呵