我有一个看起来像这样的工作配置
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。
所以我的问题是,为什么 mod_rewrite 代理对于 http 和 https 请求的工作方式与 ProxyPass 版本不同?根据我的理解,我上面的两个例子在功能上应该是等效的,但事实似乎并非如此。我缺少什么?我无法找到任何可以解释这一点的文档。谢谢!
最佳答案
尽管可能为时已晚,但我还是发布了此答案,以防有人访问此页面时遇到同样的问题。
ProxyPass 的语法与RewriteRule 的语法不同。在RewriteRule中,为了引用协议(protocol),您应该使用%{SERVER_PROTOCOL}
,如 http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html 中所述。
关于apache - ProxyPass 和 RewriteRule [P] 在 http/https 方面表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17028202/