在 Debian 测试中,我收到 Apache 的 403 错误消息。
Apache 版本:
# aptitude show apache2 | grep -i version
Version: 2.4.9-1
# ls -la /home/
total 28
drwxr-xr-x 4 root root 4096 Apr 3 13:19 .
drwxr-xr-x 23 root root 4096 Apr 4 07:28 ..
drwx------ 2 root root 16384 Apr 3 13:13 lost+found
drwx--x--x 36 username username 4096 Apr 7 13:30 username
# ls -la /home/username/Development/PHP/foo.dev.com/
total 16
drwx--x--x 4 username username 4096 Apr 3 14:35 .
drwx--x--x 6 username username 4096 Apr 3 14:36 ..
drwx--x--x 2 username username 4096 Apr 3 14:35 logs
drwx--x--x 8 username username 4096 Apr 3 14:35 public_html
# cat /etc/apache2/sites-enabled/dev.com.conf
UseCanonicalName Off
<VirtualHost *>
VirtualDocumentRoot "/home/username/Development/PHP/%0/public_html/"
<Directory "/home/username/Development/PHP/%0/public_html/">
Require all granted
</Directory>
</VirtualHost>
# cat /var/log/apache2/error.log
[Mon Apr 07 14:08:15.069251 2014] [authz_core:error] [pid 8649] [client 127.0.0.1:48578] AH01630: client denied by server configuration: /home/username/Development/PHP/foo.dev.com/public_html/
Firefox,“无代理”配置:
localhost, 127.0.0.1, *.dev.com
# cat /etc/hosts:
hosts hosts.allow hosts.deny
root@username:/home# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 username.mymachine.local username
# Custom
127.0.0.1 teste.dev.com
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
更新 1:
SELinux 似乎没有安装:
$ aptitude search ~i | grep selinux
i libselinux1 - SELinux runtime shared libraries
更新2:
$ ls -la /home/
total 28
drwxr-xr-x 4 root root 4096 Apr 3 13:19 .
drwxr-xr-x 23 root root 4096 Apr 4 07:28 ..
drwx------ 2 root root 16384 Apr 3 13:13 lost+found
drwx--xr-x 38 username username 4096 Apr 9 08:26 username
答案1
服务器配置拒绝客户端:/home/username/Development/PHP/foo.dev.com/public_html/
这让我想起了我遇到的一个类似的问题:
确保www-data
用户已x
设置位权限每个文件夹在通往/home/username/Development/PHP/foo.dev.com/public_html
通过成为www-data
文件夹的所有者:chown www-data
或者授予该x
位others
:chmod o+x
编辑 :
最后我终于能够重现了。看来指令%0
不支持<Directory>
。我已更正此问题,并添加了一个*
:
UseCanonicalName Off
<VirtualHost *>
VirtualDocumentRoot "/home/username/Development/PHP/%0/public_html/"
<Directory "/home/username/Development/PHP/*/public_html/">
Require all granted
</Directory>
</VirtualHost>
答案2
我不确定<Directory>
-directive 是否接受%0
作为路径名的一部分,在文档中只提到正则表达式:http://httpd.apache.org/docs/current/mod/core.html#directory
而“%0”是vhost_alias模块的一部分:http://httpd.apache.org/docs/current/mod/mod_vhost_alias.html
你可以尝试改变
<Directory "/home/username/Development/PHP/%0/public_html/">
到:
<Directory "/home/username/Development/PHP/">
看看是否如此。你也可以尝试使用正则表达式/home/username/Development/PHP/*/public_html/
答案3
服务器配置拒绝客户端:/home/username/Development/PHP/foo.dev.com/public_html/
显而易见的是......
ls -la /home/username/Development/PHP/foo.dev.com/
... drwx--x--x 8 用户名 用户名 4096 4月 3 14:35 public_html
...apache uid 需要对目录(和文件)具有 READ 权限。解决方法:
chmod -R o+r /home/username/Development/PHP/foo.dev.com/