我目前正在使用haproxy来做reverse_proxy。
不幸的是,我不能得到它的工作!
这是我的configuration:
backend twisted mode http timeout connect 10s timeout server 30s balance roundrobin server apache1 127.0.0.1:11111 weight 1 maxconn 512 backend cometd mode http timeout connect 5s timeout server 5m balance roundrobin server cometd1 127.0.0.1:12345 weight 1 maxconn 10000 frontend http_proxy #arbitrary name for the frontend bind *:80 #all interfaces at port 80 mode http option forwardfor option http-server-close option http-pretend-keepalive default_backend twisted #by default forward the requests to apache acl req_cometd_path path_beg /comet/ use_backend cometd if req_cometd_path acl req_cometd_host hdr_dom(host) -i comet.okiez.com use_backend cometd if req_cometd_host
放在
reqrep ^([^\ ]*)\ /comet/(.*) \1\ /\2
到您的后端定义。 这样,Haproxy就可以在前端使用该path进行路由决策。 在这里,开头的/comet请求将与req_cometd_path acl相匹配,并因此被路由到正确的后端。
在后端本身中,现在可以将请求调整为适合其后面的实际应用程序服务器。 因此,上述的规则将去掉通过彗星后端的所有请求的path开始的彗星。
编辑(添加以下内容):
关于你的第二个问题, hdr_dom只有在指定的string(在你的情况下是comet.okiez.com)被发现是孤立的或者通过标题中的点分隔时才匹配。 你可能想要使用其中之一
# matches if 'comet' is somewhere in the host acl req_cometd_host hdr_dom(host) -i comet # matches if 'comet' is at the beginning the host acl req_cometd_host hdr_beg(host) -i comet # matches if the host is comet.okiez.com acl req_cometd_host hdr(host) -i comet.okiez.com
有关更多详细信息,请参阅Haproxyconfiguration手册 。
问题1的潜在答案…
你的代码在做什么是声明哪个后端使用,但它没有做任何有关redirect等。
也许以下会帮助你…
acl req_cometd_path path_beg /comet/ redirect prefix /test1/test2/ if req_cometd_path use_backend cometd if req_cometd_path
对于第二个问题,请尝试以下内容 –
acl req_cometd_host hdr_end(host) -i comet.okiez.com use_backend cometd if req_cometd_host
注意hdr_end而不是hdr_dom ..只是一个build议。 我希望这有帮助!
您可以使用“请求replace”来即时更改url。
HAProxy文档
replace "/comet/" with "/" at the beginning of any request path. reqrep ^([^\ ]*)\ /comet/(.*) \1\ /\2
我不是100%确定操作的顺序。 (acl操作vs use_backend)
但是,我希望如果您将reqrep行放在您的cometd后端代码部分中,它将在acl之后进行处理。
你的主机头检查看起来确定。 你怎么testing它? 你在/ etc / hosts或者DNS中parsing为127.0.0.1有“comet.okiez.com”吗?
您也可以将Host:标头添加到wget请求中。
例如。
wget --header="Host: comet.okiez.com" http://localhost/