1

I have haproxy installed and it works just fine, currently I have configuration that looks as follows

frontend public_http
        # Listen on port 80
        bind *:80
        mode http
        # Define ACLs for each domain
        acl acl_webtest  hdr(host) -i -f /etc/haproxy/acls/webtest
        use_backend back_web_test if acl_webtest

backend back_web_test
        mode http
        balance roundrobin  # Load Balancing algorithm
        option httpchk
        option forwardfor
        server webtest 192.168.0.123:80 weight 1 maxconn 512 check

As you can see I am redirecting incoming HTTP traffic to the backend on the same port (80 default for HTTP).

But my question :
Is it possible to have single frontnend without bunch of bind *:<port> statements and redirect to a single backend to the same <port>. BUT only HTTP traffic. I know that default port for HTTP is 80, but we are able to send HTTP request to any port.

It looks like TCP proxy, but I need to redirect to a backend based on domain, and TCP layer (OSI 4) doesn't know anything about domain.

So I hope, I've described my problem clearly.

I would be grateful for any help.

CROSP
  • 191
  • 1
  • 1
  • 7
  • You are saying *redirect*, but you almost certainly mean to say *forward*. When you *redirect*, the proxy sends a `3XX` HTTP response to the browser, along with a `Location:` response header, the browser changes its address bar, and connects to the redirect target. TCP connections don't redirect. – Michael - sqlbot Dec 24 '16 at 22:43

1 Answers1

3

You can do this by omitting the :port on the server line

frontend public_http
    # Listen on port 80 to 1024, included
    bind :80-1024
    # Listen on ports 8088, 8080, 8000
    bind :8088,:8080,:8000
    mode http
    # Define ACLs for each domain
    acl acl_webtest  hdr(host) -i -f /etc/haproxy/acls/webtest
    use_backend back_web_test if acl_webtest

backend back_web_test
    mode http
    balance roundrobin  # Load Balancing algorithm
    option httpchk
    option forwardfor
    server webtest 192.168.0.123 weight 1 port 80 maxconn 512 check

With this configuration, the backend connection will be made to the same port the client connected to. The separate port keyword on the server line is used for health checks.

nmerdan
  • 51
  • 4