【问题标题】:URL rewriting in VirtualHost causes 403 ForbiddenVirtualHost 中的 URL 重写导致 403 Forbidden
【发布时间】:2018-07-23 19:23:12
【问题描述】:

我的前端服务器由 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/,它可以工作(在端口 1001 上有一个 Python 服务器,但这对于这个问题并不重要)。

如何解决?

【问题讨论】:

  • 你试过把RewriteRule ^/site2(.*)$ http://localhost:1002$1 [P,L]改成`198.51.100.13:1001, i,e, use the IP instead of localhost`的格式吗?
  • @ildflue 是的,同样的问题。

标签: apache mod-rewrite apache2 virtualhost apache2.4


【解决方案1】:

解决办法是:

<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

【讨论】:

    猜你喜欢
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 2013-01-26
    • 2023-01-12
    相关资源
    最近更新 更多