Load balancing: Nginx, Varnish and HTTP sessions
Solution 1:
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 static.example.com
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.
Solution 2:
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.