I'm thinking about the architecture for a new Webserver. Would having Varnish as a cache in front of Nginx as a reverse-proxy and serving static files in front of apache for all heavy lifting be a good idea?
I'm going to run php and ruby on rails applications.
Will there be too much overhead passing php requests to apache through two other processes?
Thanks a lot!
Yeah, it's valid. My personal approach would be to use Varnish up front and use VCL to split the traffic between static NGINX requests and your heavy lifting (whether that be Apache or Passenger or... it doesn't matter). This is especially true if it is on the same machine as you don't need the extra overhead. It doesn't necessarily buy you anything.
Varnish doesn't (yet) support gzip compression, so it might be an idea to swap it around with nginx in front to compress what varnish sends back. Since varnish and nginx don't fight for the same resources (nginx uses CPU for gzip compression, while varnish uses memory) they should run smoothly on the same machine.Varnish now supports gzip compression, so unless you need SSL termination (as suggested in the comments), I would suggest putting varnish directly in contact with the Internet.
For http:
For https:
If you want apache in there too (for the ubiquitous mod_foobar support), I'd put it between varnish and the application
Update: Updated to include gzip support in varnish 3.0. Added ssl / esi as suggested in comments
The amount of overhead shouldn't be significant. I'm assuming part of the reason you want to have these two tiers is for scalability; in which case you would most likely see, relative to apache, that varnish and nginx aren't working very hard.
If you all three tiers on one machine, there should be less of a performance impact before you reach the capacity of the server itself.
As an alternative, why not varnish + nginx with passenger? I've used this setup in the past and nginx using passenger is relatively light, and ran pretty well. Might be worth thinking about if you're not married to apache running your rails stack.
I am the sys admin for a startup ecommerce platform. We use varnish+nginx in front of our PHP/apache stack and it has worked wonders.
We have a high memory use application and the app was using around 15-20gigs of RAM per webnode and once we put varnish in front it is now around 8gig of RAM per node. They have never spiked.
So I highly recommend it.
I'm running Drupal, with boost module on an Apache+PHP+MySQL server, but in front of them I'm using Nginx with gzip-static feature on, and using the results of boost to serve the users.
And on the top of all of that I'm using varnish, all on the same PC, I'm having good results.
I'm also using Nginx to tweak the headers that Drupal does not do very well for cache.
It isn't a good idea unless you need something like ESI. Nginx has it's own caching system that performs better.
Apache can be used to SSL terminate (decrypt), check http://noosfero.org/Development/Varnish#SSL