2

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 ?

7
  • Varnish “not working” sounds like a configuration issue and not exactly a problem with macOS. . Perhaps this is a better fit for Webmasters?
    – Allan
    Feb 8, 2023 at 14:42
  • @Allan, it actually works because when I visit 127.0.0.1:8080, I See Varnish in the Header of the response. I may have a port pb, but what I'm reading is very confusing. I tried to move to NGINX but no success here.
    – pbonnefoi
    Feb 8, 2023 at 14:51
  • So, Varnish server is “up” but not answering requests? It definitely points to a config issue. By any chance, are you running a firewall?
    – Allan
    Feb 8, 2023 at 15:00
  • I don't think so. I just use MAMP Pro with Apache on port 80 and Varnish on port 8080 and using the official Drupal.vcl file
    – pbonnefoi
    Feb 8, 2023 at 15:09
  • 1
    Maybe the folks over at Drupal SE can assist? I don’t think you’re going to find many Varnish/Drupal experts here.
    – Allan
    Feb 8, 2023 at 15:16

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .