Hi Gabor,

Gabor Lekeny wrote:
> I would like to create a service which balances the HTTP requests on 
> many servers without passing through the traffic on the proxy:
> actually it would redirect (HTTP 3xx) to the target server.

You might be able to use the redir parameter [1] on the server line
already without having to dive into Lua. Since it follows HAProxy's
normal server selection algorithms, you wouldn't have to re-implement
(or even query) them in Lua.

To quote the docs at
http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#5.2-redir

The "redir" parameter enables the redirection mode for all GET and HEAD
requests addressing this server. This means that instead of having
HAProxy forward the request to the server, it will send an "HTTP 302"
response with the "Location" header composed of this prefix immediately
followed by the requested URI beginning at the leading '/' of the path
component. That means that no trailing slash should be used after
<prefix>. All invalid requests will be rejected, and all non-GET or HEAD
requests will be normally served by the server. Note that since the
response is completely forged, no header mangling nor cookie insertion
is possible in the response. However, cookies in requests are still
analysed, making this solution completely usable to direct users to a
remote location in case of local disaster. Main use consists in
increasing bandwidth for static servers by having the clients directly
connect to them. Note: never use a relative location here, it would
cause a loop between the client and HAProxy!

Example :

server srv1 192.168.1.1:80 redir http://image1.mydomain.com check

Best,
Holger

Reply via email to