vps udp转发(蛋疼的haproxy,原来你是这样支持请求转发的_阿福的技术BLOG_百度空间)
在一个WEB环境中 ,根据path区分静态文件和动态数据的请求 ,并把静态文件和CGI放在不同的服务器上 。
后来 ,蛋疼的现象出现了:CGI服务器上发现了对静态文件的请求!!!
GouRiDe的haproxy有BUG?
翻啊翻啊 ,居然原因就在haproxy说明文档的第一页:
==============================================================
1.1. The HTTP transaction model-------------------------------
The HTTP protocol is transaction-driven. This means that each request will leadto one and only one response. Traditionnally, a TCP connection is establishedfrom the client to the server, a request is sent by the client on theconnection, the server responds and the connection is closed. A new requestwill involve a new connection :
[CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
In this mode, called the "HTTP close" mode, there are as many connectionestablishments as there are HTTP transactions. Since the connection is closedby the server after the response, the client does not need to know the contentlength.
Due to the transactional nature of the protocol, it was possible to improve itto avoid closing a connection between two subsequent transactions. In this modehowever, it is mandatory that the server indicates the content length for eachresponse so that the client does not wait indefinitely. For this, a specialheader is used: "Content-length". This mode is called the "keep-alive" mode :
[CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
Its advantages are a reduced latency between transactions, and less processingpower required on the server side. It is generally better than the close mode,but not always because the clients often limit their concurrent connections toa smaller value.HAProxy currently does not support the HTTP keep-alive mode,but knows how to transform it to the close mode.
A last improvement in the communications is the pipelining mode. It still useskeep-alive, but the client does not wait for the first response to send thesecond request. This is useful for fetching large number of images composing apage :
[CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
This can obviously have a tremendous benefit on performance because the networklatency is eliminated between subsequent requests. Many HTTP agents do notcorrectly support pipelining since there is no way to associate a response withthe corresponding request in HTTP. For this reason, it is mandatory for theserver to reply in the exact same order as the requests were received.
Right now, HAProxy only supports the first mode (HTTP close) if it needs toprocess the request. This means that for each request, there will be one TCPconnection. If keep-alive or pipelining are required, HAProxy will stillsupport them, but will only see the first request and the first response ofeach transaction. While this is generally problematic with regards to logs,content switching or filtering, it most often causes no problem for persistencewith cookie insertion.
==============================================================
原来 ,浏览器和haproxy建立连接的时候 ,haproxy根据第一个GET(POST..)中的路径等得出转发规则 ,比如转发到服务器A 。
但是 ,浏览器会在一个连接上发送多个GET请求 ,而haproxy仅根据第一个请求的规则转发 ,不理会第二个请求的规则 ,还是继续转发给A 。
这么牛叉的代理 ,居然不支持这么基础的应用,怎一个蛋疼了得!
解决办法有:
1 、haproxy上配置force close ,让每个连接只能发一次请求 。(keep-alive的优势让他见鬼去吧)
2 、动静分离 ,采用不同的域名 。当然,为了安全 ,动态数据的haproxy可能还是需要force close的 。
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!