我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中做到這一點?