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 have to setup a load balancing system. At the moment I have two machines running Nginx 0.8.52, PHP-FPM (on unix socket) and an application based on PHP Symfony 1.4.11.

On a third machine, I have to choose a which balancer to install.

I've already used Varnish for static file caching, but I don't know if Varnish load balancing can handle Symfony PHP sessions. Another option would be Nginx load balancing with ip_hash.

Which one is the best?

Thanks in advance

share|improve this question
up vote 1 down vote accepted

Why not both? Put NginX on the front to handle gzip compression and SSL and Varnish behind it to handle caching and load balancing. The backend application will need some session sharing on DB or Memcache as suggested by Kristaps and Varnish will not cache any dynamic content that is served with Cookies or authentication, but all the rest will be ok.

The recommended setup would be for you to be to create a separated static hostname (like and serve all static content from there, without any cookies (Varnish will cache it fine since there are no cookies), and another one for the dynamic content that can be load balanced by NginX or Varnish, using a cookie for session handling, and all the backends sharing the session information as stated above.

share|improve this answer

I'm no symfony framework expert, but for load balancing purposes it is recommended to move sessions from default file based storage to memcache session handler, to allow session part of application scale above single application .

You can archive sticky sessions in varnish by VCL magic (some simple aritmetic operations on decimal representation of clients ip address, like modulus).

Varnish by design is caching server, not load balancer.Also varnish does not support SSL, which means that seperate SSL terminator (most commonly - nginx with ssl module) is needed.

I suggest that you use load balancer which is designed not for caching, but for fully dynamic web app part, like haproxy or nginx, both of which supports sticky sessions.

share|improve this answer

I think it's better to find a way to share the session data for the future nodes e.g. NAS storage or make the load balancer share the php sessions. Other option is to rewrite your application so it can use mysql database for it's sessions and again share that data over the nodes.

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.