Php

Apache 2.4 - 403 HTTP 狀態碼

  • April 9, 2014

我在 Debian 測試中收到 Apache 的 403 錯誤消息。

阿帕奇版本:

# 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

客戶端被伺服器配置拒絕:/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

或授予xotherschmod o+x

編輯 :

最後我已經能夠重現了。指令中似乎%0不支持這一點。<Directory>我已經更正了這個添加 a *

UseCanonicalName Off
<VirtualHost *>
   VirtualDocumentRoot "/home/username/Development/PHP/%0/public_html/"
   <Directory "/home/username/Development/PHP/*/public_html/">
       Require all granted
   </Directory>
</VirtualHost>

引用自:https://serverfault.com/questions/587418