在VirtualHost中重写URL导致403被禁止



我的前端服务器由Apache 2.4。

处理

我希望在访问http://198.51.100.13/site1/时,它会自动将流量重定向到我的服务器的端口1001:

<VirtualHost *:80>
ServerName 198.51.100.13
<Directory "/">
Require all granted
</Directory>
RewriteEngine On
RewriteRule ^/site1(.*)$ http://localhost:1001$1 [P,L]
RewriteRule ^/site2(.*)$ http://localhost:1002$1 [P,L]
RewriteRule ^/site3(.*)$ http://localhost:1003$1 [P,L]
</VirtualHost>

问题:打开http://198.51.100.13/site1/时我会遇到此错误:

403:禁止
您无权在此服务器上访问/areallybigpage。

另一方面,如果我做http://198.51.100.13:1001/,它可以工作(有一个Python Serveron端口1001,但这对这个问题并不重要(。

(。

如何解决此问题?

解决方案是:

<VirtualHost *:80>
ServerName 198.51.100.13
RewriteEngine On
RewriteRule ^/site1(.*)$ http://localhost:1001$1 [P,L]
RewriteRule ^/site2(.*)$ http://localhost:1002$1 [P,L]
RewriteRule ^/site3(.*)$ http://localhost:1003$1 [P,L]
</VirtualHost>

,但不要忘记做:

a2enmod proxy  
a2enmod proxy_http       # I forgot this one!
a2enmod proxy_wstunnel   # mandatory if using websockets
service apache2 restart

最新更新