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 want to setup a Squid reverse proxy that splits HTTP traffic to two web servers for load balancing, and have it use persistence (so if a user gets to webserver1 with a first request their second request goes to webserver1 also.)

Other reverse proxy solutions I've worked with have done this by injecting a session cookie into the HTTP stream; how can I do this using squid?

share|improve this question
up vote 1 down vote accepted

Say your servers are at and You'll want something like this:

cache_peer parent 80 0 no-query originserver sourcehash
cache_peer parent 80 0 no-query originserver sourcehash

It'll do a hash of the client's IP address and direct a given client to the same upstream server with each request (as long as the upstream servers stay up) based on that.

share|improve this answer
Two problems with this: 1. (Not a biggie) Large organizations that NAT to a single IP outside will end up on the same web server; 2. (More serious) Clients that change IPs during a single session will break. – Max Alginin Apr 15 '11 at 5:40
@ynguldyn Yup, cookie-based routing is more reliable and provides more consistently balanced client distribution, but I don't believe that it's supported by Squid? Depending on the application and the target users, this may work just fine for his needs. IP hashing is the best recommendation that I've got when the scope is limited to Squid. – Shane Madden Apr 15 '11 at 5:50

Squid is not a good load balancer. It just doesn't have the necessary functionality. Use (or persuade the decision makers) HAProxy.

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.