2015-10-13 56 views
0

我試圖做一個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 

正如你可以看到,升級和連接頭被剝離出來。 有什麼方法可以轉發一切嗎?

回答

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」 協議。它需要它來觸發升級。

代碼的工作原理是這樣的,但你也應該修改協議/ mod_proxy_wstunnel文件,並使其更通用。