apache - ProxyPass 和 RewriteRule [P] 在 http/https 方面表现不同

标签 apache mod-rewrite mod-proxy

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

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/

相关文章:

php - htaccess : disallow all pdf files but allow from php script (file download script)

java - 使用 HttpComponents 基于客户端证书的身份验证

linux - ColdFusion 是否在 Linux 上安装/运行?

apache - 如何通过 https 使用 Vagrant & Puppet

regex - 专门处理一个查询参数

apache - 转发 HTTPS 代理 Apache 不工作并且没有日志

apache - WWW 到 NON WWW Urls(删除 WWW)使用 Apache (.htaccess)

regex - 如何从单个页面中删除 .php 或 .html 扩展名?

tomcat - AJP 1.3 连接器在全局监听端口 8009,为什么以及如何关闭它?

node.js - 如何使用示例在端口 80 上运行 sails.js 应用程序?