Set up Varnish locally on a Mac OS with MAMP Pro

homebrewmamp

I'm trying to make Varnish work on my local Mac with MAMP Pro (running a Drupal website). I have installed Varnish with Homebrew

brew install varnish

So far so good. Then I start Varnish with the following command :

sudo varnishd -a 127.0.0.1:8080 -T 127.0.0.1:6082 -f /usr/local/etc/varnish/drupal.vcl -s file,/tmp,500M

The varnish child start and I start to monitor with :

varnishstat

MAMP Pro is set to port 80 which is the conf I have in my .vcl file. The problem is Varnish does not cache the page when I go to my http://drupal.local website (All the caching conf from Drupal is properly set up as it works on a centOS server).

Any idea about what I'm missing ?

Best Answer

Here is the solution and what I was missing. My vhost was in HTTPS and working with Varnish it's easier to work with HTTP.

Here is all the step that might help someone :

Make sure that Apache in MAMP Pro is running on port 80.

In the VCL file make sure that Varnish targets port 80. Mine was looking like that :

backend default {
  .host = "127.0.0.1";
  .port = "80";
}

Then I start varnish with the following command (varnish running on port 8080) :

sudo varnishd -a :8080 -T localhost:6082 -f /usr/local/etc/varnish/drupal.vcl -s file,/tmp,500M

When I visit http://my-vhost.local:8080/node/1 varnish is properly caching the page. If I go to http://my-vhost.local/node/1, I see the page without varnish.

To clear the varnish cache of the page I just do this command :

curl 'http://my-vhost.local:8080/node/1' -X PURGE