Nginx – Caching: Varnish vs fastcgi_cache on Nginx in a multiple websites envirnment

fastcginginxphp-fpmreverse-proxyvarnish

I have a setup of a VPS with several websites. Some of the websites are WP websites and some of them are other dynamic websites.

I'm interested in adding a sort of reverse proxy/caching layer. However I don't want to cache all the websites…

I've seen that a lot of people recommend using Varnish. The problem I found in Varnish is that it takes Port 80 and caches everything.

When I was looking for solutions, or ways to avoid cache for some websites, I found about fastcgi_cache. Apparently, you can cache directly through Nginx into files and then serve it statically. I've also seen somewhere that you can cache from Nginx into memcached, but I don't know how yet.

Anyway, here are my options:
1. Using Varnish and somehow tweaking the config files to pass requests based on Domain name.
2. Using fastcgi_cache on Nginx.
3. Using a sandwich. Having Nginx listening to port 80, serving the static files and sending all the php files to Varnish on another port which will pass all the uncached users to another Nginx instance.

What do you think that I should do?

Thanks.

Best Answer

You can have Varnish pass some requests through based on domain name, it's very easy and Varnish won't noticeably slow down the websites you aren't caching.

You just add a little VCL code in vcl_recv like:

if (req.http.Host == "www.pass_this_thru.com") {
    return(pass);
}