2016-07-07 51 views
0

我serverA的與HAProxy的和配置:HAProxy的應用服務器響應其它端口

global 
     log 127.0.0.1 local0 
     log 127.0.0.1 local1 notice 
     maxconn 4096 
     daemon 

defaults 
     log  global 
     mode http 
     option httplog 
     option dontlognull 
     retries 3 
     option redispatch 
     maxconn 2000 
     contimeout 5000 
     clitimeout 50000 
     srvtimeout 50000 

frontend http-in 
     bind *:80 
     default_backend servers 

backend servers 
     option httpchk OPTIONS/
     option forwardfor 
     stats enable 
     stats refresh 10s 
     stats hide-version 
     stats scope . 
     stats uri  /admin?stats 
     stats realm Haproxy\ Statistics 
     stats auth admin:pass 

     cookie JSESSIONID prefix 
     server tomcat1 serverB:10039 cookie JSESSIONID_SERVER_1 
     server tomcat2 serverC:10039 cookie JSESSIONID_SERVER_2 

現在,我去http://serverA/admin?stats,得到了統計。在服務器serverB和serverC上安裝了WebSphere Application Server和WebSphere Portal Server(它與Tomcat和WPS類似,就像任何部署到Tomcat的應用程序一樣)。它主機在端口100039.現在我去http://serverA/wps/portal並得到我的門戶網站,但是當我點擊任何頁面的任何鏈接,我得到重定向到http://serverA:100039/wps/portal/bla/bla,這是因爲WPS響應其端口 - 100039,但我的haproxy配置只聽80端口。我已經試過:

option forwardfor 
http-request set-header X-Forwarded-Port %[dst_port] 
http-request add-header X-Forwarded-Proto https if { ssl_fc } 
option httpchk HEAD/HTTP/1.1\r\nHost:localhost 

舉一個例子,在nginx的我得到這樣的:在3000端口和我的nginx的配置的一部分有用

我的應用程序的主機看起來是這樣的:

location @ruby { 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 
     proxy_read_timeout 300; 
     proxy_pass http://app; #upstream app 
} 

我如何在HAProxy中做到這一點?

回答

0

這個問題類似於WebSphere Portal behind reverse proxy and getServerPort()

我認爲這個問題是在WebSphere Application Server(傳統)不接受主機頭得當,這會影響越來越反向代理工作。

嘗試在其他答案中推薦的設置(調整haproxy的apache配置設置),並且一切都會好的。

0

在你的後端部分,使用「http請求設置頁眉」設置$ WSSP$ WSSN你的客戶可視主機名和端口。然後它們將被用於自引用重定向。

或者,將websphere自定義屬性trusthostheaderportcom.ibm.ws.webcontainer.extractHostHeaderPorthttp://www-01.ibm.com/support/docview.wss?uid=swg21569667)設置爲尊重Host:頭中的端口。

使用此選項,您可能需要在HBAroxy的後端部分中使用「http-request set-header Host」將主機頭設置爲客戶端視圖。我不確定默認是什麼。