Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set up an HAProxy that will listen on port 80 and roundrobin redirect location any traffic to two servers along with doing the health check.

The servers have different URL's so afaik I can't use server <name> <ip>:<port> check lines as I want the client's browser to read https:/// or

Here's my haproxy.cfg:

        log   local0
        log   local1 notice
        #log loghost    local0 info
        maxconn 4096
        user haproxy
        group haproxy

        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen webfarm *:80
       mode http
       stats enable
       stats auth admin:apassword
       balance roundrobin
       option forwardfor
       redirect location
       redirect location

Any pointers would be greatly appreciated. This is my first adventure with HAProxy or any software NLB.


share|improve this question
up vote 1 down vote accepted

I don't think you can balance redirects. If the purpose of this deployment is to redirect all traffic to these servers from http to https, you'll want to listen on two separate IPs, and redirect accordingly. This will mean that the user must know the subdomains in advance.

What you're attempting to do strikes me as not so good. A user is going to hit your frontend URL, and be redirected to one of two subdomains. If they return, they may be redirected to the other subdomain. As a user, I'd find this extremely awkward.

The purpose of load balancing, is obscuring the implementation details of how many and what servers are in the cluster, and provide a uniform front end.

I'd suggest something along the lines of the following:

Frontend: #
Backend 1:
Backend 2:

In each of the backends, have their default page load at /gohere rather than trying to get HA Proxy to rewrite the URL. Now you can load balance all you want, obscure the details from the user.

If you REALLY want to achieve the rewriting of the subdomains, you could attempt something like this:

Frontend: #
balance roundrobin
Backend: server
Backend: server

Frontend: #
redirect location

Frontend: #
redirect location

However, you'd need to install HA Proxy on all 3 hosts (unless any of the above backends share a host and have multiple NICs).

If you're using Apache as the backends, you can achieve https redirects very very simply and shouldn't manage this with HA Proxy.

share|improve this answer

I think I get what you want, but not 100% sure. I think you need to rewrite the "listen" stanza as two separate "frontend" and "backend" stanzas. That way you should be able to add a check to the backends but still have your redirect/URL-mangle in place.

Have a look at some of the haproxy examples, "listen" is used for short and complete rule sets, but backend+frontend is used for more complicated setups.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.