2

我有一个看起来像的工作配置

ProxyPass /roundcube protocol://127.0.0.1:8080/roundcube
ProxyPassReverse /roundcube protocol://127.0.0.1:8080/roundcube

当我去

http://www.example.com/roundcube
or
https://www.example.com/roundcube

正如预期的那样,两者或正确代理到 127.0.0.1:8080 上的服务器。

但是,我想更好地控制代理何时发生,所以我想使用 mod_rewrite 的 [P] 选项而不是上面显示的 ProxyPass 指令。我尝试了以下方法:

RewriteEngine On
RewriteRule ^/roundcube$ /roundcube/ [R]
RewriteRule ^/roundcube/(.*) protocol://127.0.0.1:8080/roundcube/$1 [P]
ProxyPassReverse /roundcube protocol://127.0.0.1:8080/roundcube

有了这个配置,当我去

http://www.example.com/roundcube

请求代理按预期正确。

但是当我去

https://www.example.com/roundcube

请求 404 的。

所以我的问题是,对于 http 和 https 请求,为什么 mod_rewrite 代理的工作方式与 ProxyPass 版本不同?根据我的理解,我上面的两个示例在功能上应该是等效的,但似乎并非如此。我错过了什么?我无法找到任何可以解释这一点的文档。谢谢!

4

1 回答 1

2

尽管可能为时已晚,但我会发布此答案,以防有人来到此页面时遇到同样的问题。

ProxyPass 的语法与RewriteRule的语法不同。在RewriteRule中,为了引用协议,您应该按照http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html%{SERVER_PROTOCOL}中的说明使用

于 2015-08-13T05:07:19.347 回答