Varnish3 + Drupal7 + Nginx with Multiple sites

Events happening in the community are now at Drupal community events on www.drupal.org.
Baber Javed's picture

I've been trying out several VCL files across the web but my problem seems to be a bit different. I have several websites (Rails + PHP) running on my server on Nginx + PHP-FDM on port 80 and I need to setup Varnish for one of my Drupal websites only so I obviously cannot change the port 80 to be used by Varnish as all the other sites will go down as well.
Any Ideas what my VCL file should look like in this case? (PHP-FDM is running on port 9000)

Comments

Make sure you're using

alanmackenzie's picture

Make sure you're using varnish 3.0 from the varnish repository, the 'native' packages are quite out of date.

Either start varnish on a separate interface and migrate the DNS for your sole drupal site or route all traffic through varnish, bind nginx to a different port or localhost only and write some custom VCL to select the correct backend depending on the host header.

e.g.

backend php {
  .host = "127.0.0.1";
  .port = "9000";
}

backend rails {
  .host = "127.0.0.1";
  .port = "8080";
}

sub vcl_recv {

  if (req.http.host ~ "my-example-php-site.com$") {
     set req.backend = php;
  }
  else {
    set req.backend = rails;
  }

  .....

}

The above isn't a complete solution, you'll need to read this:
https://www.varnish-cache.org/docs/3.0/reference/vcl.html

Thanks

Baber Javed's picture

Thanks, finally got it working. But for some reason some of the pages always report a MISS for X-Varnish-Cache, why would that be.

P.S I've got it working on the website www.pakreviews.com

When I visit the homepage I

alanmackenzie's picture

When I visit the homepage I get:

Via   1.1 varnish
X-Drupal-Cache  MISS
X-Generator    Drupal 7 (http://drupal.org)
X-Powered-By   PHP/5.3.10
X-Varnish    553209247 553208211
X-Varnish-Cache HIT

You probably just need to clear your cookies after logging out as by default varnish will pass any requests with a Set-Cookie header and thus generate a MISS.

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: