Forbidden
You don't have permission to access / on this server.
本地 https://localhost/test.php 正常,但用內網 IP https://10.10.50.195/test.php 訪問報 403。典型原因:Apache httpd.conf 中 Directory 指令默認拒絕非本地訪問。
<Directory /><Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
# Deny from all # 註釋掉拒絕所有
Allow from all # 允許所有來源訪問
Satisfy all
</Directory>
<Directory "D:/Wamp5/www"><Directory "D:/Wamp5/www">
Options Indexes FollowSymLinks
AllowOverride All
Order Deny,Allow
# Deny from all # 註釋掉
# Allow from 127.0.0.1 # 註釋掉僅本地
Allow from all # 允許所有 IP
</Directory>
關鍵點: Apache 2.2 使用 Order Deny,Allow + Allow from all;Apache 2.4+ 改用 Require all granted。請根據安裝版本選擇語法。
| 指令 | Apache 2.2 | Apache 2.4+ |
|---|---|---|
| 允許所有 | Order allow,deny Allow from all | Require all granted |
| 拒絕所有 | Order deny,allow Deny from all | Require all denied |
| 允許特定 IP | Order deny,allow Allow from 192.168.1.100 | Require ip 192.168.1.100 |
| 允許特定域名 | Allow from example.com | Require host example.com |
| 混合認證 | Satisfy any/all | <RequireAny> / <RequireAll> |
httpd.conf(或 httpd-vhosts.conf 虛擬主機配置)。C:\xampp\apache\conf\httpd.conf 及 extra\httpd-vhosts.conf。/etc/httpd/conf/httpd.conf (RHEL/CentOS) 或 /etc/apache2/apache2.conf (Debian/Ubuntu),站點配置在 sites-available/。httpd.conf。wampapache64 / Apache2.4;或命令行 httpd -k restart。systemctl restart httpd / systemctl restart apache2。<Directory "D:/wwwroot">
Options Indexes FollowSymLinks
AllowOverride All
# Apache 2.2
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from 10.0.0.0/8
Allow from 192.168.0.0/16
Allow from 172.16.0.0/12
# Apache 2.4
# Require ip 127.0.0.1 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12
</Directory>
apachectl -t -D DUMP_INCLUDES 查看加載順序)。.htaccess 是否覆蓋了目錄權限(AllowOverride All 允許覆蓋)。setsebool -P httpd_can_network_connect 1 或臨時 setenforce 0 測試。rx 權限,對文件有 r 權限。chmod -R 755 /var/www/html。<VirtualHost> 內是否有獨立 <Directory> 覆蓋全局設置。