"Require all granted" 在 Apache VirtualHost 配置中,但仍然 "You don't have permission to access /test on this server"(RewriteRule 失败)
"Require all granted" in Apache VirtualHost config but still "You don't have permission to access /test on this server" (RewriteRule fails)
以下是 /etc/apache2/sites-available/000-default.conf
Debian 上 Apache 2.4 配置文件的完整内容:
<VirtualHost *:80>
ServerName 203.0.113.0
DocumentRoot /home/www/203.0.113.0
<Directory "/">
Require all granted # as required with Apache 2.4
</Directory>
RewriteEngine On
RewriteRule ^/test(.*)$ /index.html [P,L]
</VirtualHost>
a2enmod rewrite
已执行,因此 mod_rewrite
已启用(由显示 rewrite_module (shared)
的 apachectl -t -D DUMP_MODULES
确认)
从浏览器访问 http://203.0.113.0/
有效,并成功显示文件 /home/www/203.0.113.0/index.html
service apache2 restart
已经执行
问题:为什么访问http://203.0.113.0/test
显示:
Forbidden
You don't have permission to access /test on this server.
Apache/2.4.25 (Debian) Server at ... Port 80
终于
cat /var/log/apache2/error.log
给出解决方案:
AH00669: attempt to make remote request from mod_rewrite without proxy enabled
所以
a2enmod rewrite proxy proxy_http
解决了问题。
以下是 /etc/apache2/sites-available/000-default.conf
Debian 上 Apache 2.4 配置文件的完整内容:
<VirtualHost *:80>
ServerName 203.0.113.0
DocumentRoot /home/www/203.0.113.0
<Directory "/">
Require all granted # as required with Apache 2.4
</Directory>
RewriteEngine On
RewriteRule ^/test(.*)$ /index.html [P,L]
</VirtualHost>
a2enmod rewrite
已执行,因此mod_rewrite
已启用(由显示rewrite_module (shared)
的apachectl -t -D DUMP_MODULES
确认)从浏览器访问
http://203.0.113.0/
有效,并成功显示文件/home/www/203.0.113.0/index.html
service apache2 restart
已经执行
问题:为什么访问http://203.0.113.0/test
显示:
Forbidden
You don't have permission to access /test on this server.
Apache/2.4.25 (Debian) Server at ... Port 80
终于
cat /var/log/apache2/error.log
给出解决方案:
AH00669: attempt to make remote request from mod_rewrite without proxy enabled
所以
a2enmod rewrite proxy proxy_http
解决了问题。