Mixing varnish/WordPress & Rails on a single droplet

  • Posted March 4, 2013

I’ve got one droplet, currently set up to serve both WordPress via nginx/php5-fpm and Rails via passenger. I’m trying to set varnish up in a way where it’s only being used for the WordPress sites, but not for the Rails sites.

I followed the guide in the tutorial setup section, and here’s my config setup:

Any attempt to access (WordPress) just loads up the first site configured, i.e. (Rails). It looks like varnish is passing something along to nginx, nginx goes ‘Err, don’t know that server/port, here, have the default one instead’.

I have tried playing around with the listen directive. using from the tutorial e.g. didn’t help.

The setup I want is for varnish to immediately pass any Rails site I’m accessing to nginx, and handle caching for any WordPress sites as needed.

So I think my current problem isn’t even related to varnish yet. It’s purely an nginx config issue, getting multiple server blocks to listen on different ports. After that’s solved, I’m going to need to have all the nginx sites (even the Rails ones) run on prt 8080 presumably.

(Note that right now, I have Varnish disabled until I figure this out, so loads up just fine again, just with no caching).


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Answering my own question here… I’m actually not entirely sure how I ended up fixing it. I switched all the server entries in nginx over to listen at 8080, restarted nginx and varnish a few times during testing, tried a few various things, and now it seems to work. <br> <br>For a while, it sounded like I might need to use the nginx’s port_in_redirect option, or explicitly tell WordPress that the WordPress Address (URL) ends in port 8080, but after I removed both of those again, it’s still working. <br> <br>Here’s what I ended up putting in my default.vcl, to have varnish skip trying to handle anything but my 2 WordPress sites (i.e. the Rails apps, which tend to be on subdomains off of on the droplet: <br> <br>sub vcl_recv { <br> # Skip Rails sites <br> if ( ~ “” || <br> == “” || <br> ~ “^” ) { <br> # Drop any cookies sent to Wordpress. <br> if (!(req.url ~ “wp-(login|admin)”)) { <br> unset req.http.cookie; <br> } <br> } else { <br> return (pass); <br> } <br>} <br> <br>FWIW, pages are being served 4-5 times faster with varnish according to AB. Not super great, but not bad either.