代理升级HTTP1.1(https:// IP1:443到http:// IP2:8080)使用Apache 2
问题描述:
我试图做一个SSL代理使用Apache 2侦听端口443并转发请求基于上下文不同的IP /端口:代理升级HTTP1.1(https:// IP1:443到http:// IP2:8080)使用Apache 2
场景:
做一个JBOSS “HTTPS的远程处理” 请求(它使用HTTP1.1升级到 “的jboss-远程” 在Wildfly 8.2),从:
https://xxxxxxx.com:443
并将其转发至:
http://192.168.x.y:8080
我发现下面的RewriteCond的作品:
RewriteCond %{HTTP:Upgrade} jboss-remoting [NC]
RewriteRule ^/(.*)$ http://192.168.x.y:8080/$1 [P]
但我不能找出重写规则,我应该为了申请去请求HTTP的远程处理而不是http。
阿帕奇输入:
GET/HTTP/1.1\r\n
Sec-JbossRemoting-Key: WJaD+AcnutfrXiBna+KL5w==\r\n
Upgrade: jboss-remoting\r\n
Host: xxxxxxx.com\r\n
Connection: upgrade\r\n
阿帕奇输出:
GET/HTTP/1.1\r\n
Host: xxxxxxx.com\r\n
Sec-JbossRemoting-Key: WJaD+AcnutfrXiBna+KL5w==\r\n
X-Forwarded-For: 192.168.x.y\r\n
X-Forwarded-Host: xxxxxxx.com\r\n
X-Forwarded-Server: xxxxxxx.com\r\n
Connection: Keep-Alive\r\n
正如你可以看到,升级和连接头被剥离出来。 有什么方法可以转发一切吗?
答
找到解决方案。它由黑客攻击Apache 2.4+中的mod_proxy_wstunnel以支持jboss-remoting升级。
由于快速的黑客,你需要编辑以下文件:
mod_proxy_wstunnel.c
强制修改:
buf = apr_pstrdup(p, "Upgrade: WebSocket" CRLF "Connection: Upgrade" CRLF CRLF);
到
:升级头需要从修补
buf = apr_pstrdup(p, "Upgrade: jboss-remoting" CRLF "Connection: Upgrade" CRLF CRLF);
及以下行:
if (!upgrade || strcasecmp(upgrade, "WebSocket") != 0)
到
if (!upgrade || strcasecmp(upgrade, "jboss-remoting") != 0)
现在,一个简单的重写规则将使招:
RewriteRule ^/(.*)$ ws://IP2:8080 [P]
公告的 “WS” 协议。它需要它来触发升级。
代码的工作原理是这样的,但你也应该修改协议/ mod_proxy_wstunnel文件,并使其更通用。