【问题标题】:ProxyPass and RewriteRule [P] acting differently in regard to http/httpsProxyPass 和 RewriteRule [P] 在 http/https 方面表现不同
【发布时间】:2013-06-06 08:43:58
【问题描述】:

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

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 版本不同?根据我的理解,我上面的两个示例在功能上应该是等效的,但事实并非如此。我错过了什么?我无法找到任何可以解释这一点的文档。谢谢!

【问题讨论】:

    标签: apache mod-rewrite mod-proxy


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-25
      • 2010-10-27
      • 2014-09-02
      • 2015-11-22
      • 2019-01-03
      • 2018-04-11
      • 2017-10-15
      • 2017-07-31
      相关资源
      最近更新 更多