我有一个haproxy节点和3个应用程序服务器(tomcat)。 用户必须打开http://10.0.0.1 (通过IP地址),然后redirect到http://10.0.0.2/app或http://10.0.0.3/app或http://10.0.0.4/app 。
目前haproxyconfiguration:
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice chroot /var/lib/haproxy user haproxy group haproxy daemon maxconn 50000 defaults log global mode http option httplog option dontlognull # option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www retries 3 redispatch contimeout 1s clitimeout 2s srvtimeout 3s errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http listen stats :1941 mode http stats enable stats hide-version stats realm Haproxy\ Statistics stats uri / stats auth xxx:xxx listen appfarm 10.0.0.1:80 mode http stats enable stats auth xxx:xxx balance source hash-type consistent option httpclose option forwardfor # option httpchk HEAD /check.txt HTTP/1.0 server app01 10.0.0.2:8080/app check server app02 10.0.0.3:8080/app check server app03 10.0.0.4:8080/app check
使用该configuration,我从地址10.0.0.1:8080获得了tomcat欢迎页面,没有/ app地址。
你不能像这样在服务器行上添加一个path,你会想在服务器行上面的监听块中使用redirect:
redirect location /app if { url / }
并将您的服务器线转换为
server app01 10.0.0.2:8080 check