我拥有一个像xyz.com这样的域名,我试图用haproxyredirect其他IP地址的子域名。
我在服务器上使用tomcat,并使用haproxy将端口80上的传入请求redirect到端口8080。
Like; www.xyz.com -> 10.0.0.1 www.xyz.com/abc -> 10.0.0.2 or abc.xyz.com -> 10.0.0.2
为了做这个redirect,我该如何设置haproxy?
在haproxy中,你可以结合acl规则和redirect 。 您使用backend规则select正确的服务器。
官方的haproxy文档不是很容易阅读,但是非常完整。
像这样的东西(只是一个草图给你一个想法):
frontend http-in mode http bind FRONTENDIP:80 # eg. 100.100.100.100:80 default_backend tomcat_server_2 acl tomcat_1 hdr_end(host) -i www.xyz.com acl tomcat_2 hdr_end(host) -i abc.xyz.com acl tomcat_path path_beg /abc/ use_backend tomcat_server_1 if tomcat_1 !tomcat_path backend tomcat_server_1 server tomcat1 10.0.0.1:8080 maxconn 1000 backend tomcat_server_2 server tomcat2 10.0.0.2:8080 maxconn 1000
如果您想将 www.xyz.com/abc/ redirect到abc.xyz.com :
redirect prefix http://abc.xyz.com if tomcat_path
Haproxy既不意味着redirect名称也不redirectURI。
名称由名称服务器(DNS)指挥。
URI被Web服务器(HTTP)的(模块)redirect。
Haproxy是平衡两个(或更多)相同的服务器之间的stream量(TCP / IP)。