Squid reverse proxy – load balance to two web servers with connection persistence

httpreverse-proxysquid

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?

Best Answer

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

cache_peer 10.0.0.51 parent 80 0 no-query originserver sourcehash
cache_peer 10.0.0.52 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.