I'm looking for an HTTP load balancer that will handle server errors silently. What i want is to load balance every single request so that it works out, in the worst case with a little of timeout.

  • If the working web node returns an HTTP 500 server error, the load balancer will have to retry the request with another web node. If the second node does return another 500 error, doing the same with the last node (i suppose to have 3 nodes). If the last node returns a 500 error, display it to the end user.

  • If a server node timeout (takes more than 1 or 2 second to answer) the request will have to be routed to another server, the client should receive a good answer within 2+ seconds.


You can nginx with HttpProxyModule (it's pretty standart module and usually is inside nginx) to implement such load balancer.

Nginx is lightweight, fast and has a lot of functionality (you can even embed lua code in it).

Example config for your use case would be

upstream backend { 
server {
   listen      80;
   server_name _;

   location / {
        proxy_pass  http://backend;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

The secret sauce is proxy_next_upstream directive, which determines in what cases the request will be transmitted to the next server. Possible values are :

  • error — an error has occurred while connecting to the server, sending a request to it, or reading its response;
  • timeout — occurred timeout during the connection with the server, transfer the request or while reading response from the server;
  • invalid_header — server returned a empty or incorrect answer;
  • http_500 — server returned answer with code 500
  • http_502 — server returned answer with code 502
  • http_503 — server returned answer with code 503
  • http_504 — server returned answer with code 504
  • http_404 — server returned answer with code 404
  • off — it forbids the request transfer to the next server
  • It looks like to be amazingly easy. I will check it during the we and most probably award you the bounty, thank you! ;) – cedivad Mar 5 '13 at 15:38

I'm guessing you want to serve HTTP?

Nginx provides a lot of functionalities, including all the ones you are looking for: http://wiki.nginx.org

check especially the upstream and proxy settings, there you can implement all your requirements: http://wiki.nginx.org/HttpUpstreamModule http://wiki.nginx.org/HttpProxyModule


Another possible solution to implement your requirements is LVS (Linux Virtual Servers) which are implemented in the Linux kernel itself. if you just google for LVS tutorial you will get tons of results.


What you're looking for here is either a proxy or a reasonably expensive load-balancer.

On the proxying side, squid/nginx can do the job relatively reasonably - which you go with is somewhat a matter of preference, but also how important it is to have the kitchen sink at your disposal (if it's not, nginx is arguably the best choice)

On the hardware side of things... an F5 load balancer can do this sort of thing whilst also ensuring high scalability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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