我正在尝试使用Apache 2来侦听端口443,并根据上下文在不同的IP /端口上转发请求:
情景:
制作一个jBoss“https-remoting”请求(它使用HTTP1.1升级到Wildfly 8.2中的“jboss-remoting”),来自:
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]
但我无法弄清楚我应该应用什么RewriteRule才能让http-remoting不是http。
Apache输入:
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
Apache输出:
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
如您所见,升级和连接标头已被删除。 有没有办法可以转发一切?
答案 0 :(得分:0)
找到解决方案。它包括从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”协议。它需要它才能触发升级。
代码的工作方式与此类似,但您也应修补protocol / mod_proxy_wstunnel文件,并使所有内容更通用。