Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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've finally got HA Proxy set up and running in a way I think I want. However, it is not load balancing the web requests it receives. All requests are currently being forwarded to the first server in the cluster. I'm going to paste my configuration below - if anyone can see where I may have gone wrong, I'd appreciate it.

This is my first stab at configuring web servers in a *nix environment.

First up, I have HA Proxy running on the same host as the first server in the apache cluster. We are moving these servers to virtual later on, and they will have different virtual hosts, but I wanted to get this running now.

Both web servers are receiving their health checks, and are reporting back correctly. The haproxy?stats page correctly reports servers that are up and down. I've tested this by altering the name of the file that is checked. I haven't put any load onto these servers yet. I've just opened up the URLs on several tabs (private browsing), and had several co-workers hit the URL too. All of the traffic goes to WEB1. Am I balancing incorrectly?

      maxconn 10000
      nbproc 8
      pidfile /var/run/
      log local0 debug

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

listen WEBHAEXT :80,:8443
      mode http
      cookie sessionbalance insert indirect nocache
      balance roundrobin
      option httpclose
      option forwardfor except
      option httpchk HEAD /health_check.txt
      stats enable
      stats auth rah:rah
      server WEB1 cookie WEB_1 check
      server WEB2 cookie WEB_2 check


I successfully ran tests using ab (apache benchmarking) and load was split evenly across both nodes. I'm not sure what I was doing wrong before, but the above configuration works.

share|improve this question
What does a stats page show? Is one of the backend servers in down state? – Alex Feb 4 '11 at 8:09
No, both servers are up when I'm testing this. – Josh Smeaton Feb 5 '11 at 1:40
up vote 3 down vote accepted

How are you checking that all requests go to a single server? As you've configured HAProxy, you're using sticky sessions where HAProxy sets a cookie on each client that directs it to the same backend node for every request. If you simply kept reloading in a single browser, you'd see every request go to the same backend.

share|improve this answer
I was opening new incognito windows and checking the cookie that was set, and viewing load on the stats page. Like I said, I also had several co-workers on different machines hit the proxy and everyone was sent to WEB1. – Josh Smeaton Feb 5 '11 at 1:42
+1, it may not be the problem in this case, (if it's not cookies and both servers are up - i don't know!) but cookies are something really easy to forget about. I opt for doing "curl -I <url>" when testing the setup so I can see the headers returned each time. (curl doesn't honour cookies by default). – Coops Feb 7 '11 at 23:09
First to answer correctly (before I posted the bounty), so you get the win. I don't know why it wasn't appearing to balance before, but it is now. – Josh Smeaton Feb 9 '11 at 10:22

I've just tried the exact config you provided. Firstly the health check didn't work for me, I had to add a "/" infront of "health_check.txt" (haproxy-1.4.10).

However the load balancing worked fine. Each time I closed and re-opened my browser I'd be pinged across to the other server.

Do you have a live application you're testing (with it's own cookies), or is it just a test page?

share|improve this answer
You're right about the health check, but I removed the /path/to/health_check.txt and forgot to leave the /. You're right about the load balancing, it does work fine. – Josh Smeaton Feb 9 '11 at 10:22
Bounty given (but not right answer) because of the effort to test the config. Thank you muchly! – Josh Smeaton Feb 9 '11 at 10:28
@John pleasure :) – Coops Feb 9 '11 at 10:31

Try to remove insert statement from cookie.

Following to documentation for [insert]:

If the client has all the required information to connect to the same server next time, no further cookie will be inserted.

So, it's possible that all requests get their WEB1 assigment via this cookie and then follow this direction on each request.

PS: And you must set same names for cookie parameter in server statement.

server WEB1 cookie WEB_LB check
server WEB2 cookie WEB_LB check
share|improve this answer
@Molokov I don't believe your comment regarding cookies to be accurate. In the server statement, you assign the value of the cookie, where the name of the cookie is defined in the listen/backend section. – Josh Smeaton Feb 9 '11 at 10:26

Did you try to remove every option involved in cookie-based persistence? What happens?

Try to change WEB_1 into WEB1:

server WEB1 cookie WEB1 check
server WEB2 cookie WEB2 check
share|improve this answer
The underscores in the cookie values work correctly. – Josh Smeaton Feb 9 '11 at 10:26

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.