My apologies if that question is already asked - I searched thru all related questions but found a similar not exact match to my problem.

What is my set:

  1. Magento 2.4.3 running on Ubuntu 22.04 server with Apache 2
  • Magento is set to production mode

What I've done to try enabling Varnish:

  1. I've installed varnish on my Ubuntu server
  2. I've enabled the Varnish cache from Magento Admin Panel
  • Access list & Backend host is to be equal to my Server's IP
  1. VCL file is exported to the varnish directory and replaces the default.vcl file (with the same name)
  2. I've restarted both Varnish and Apache services
  3. run Magento (compile, upgrade, cache clean, and static content deploy)

I follow that instruction https://experienceleague.adobe.com/en/docs/commerce-operations/configuration-guide/cache/configure-varnish-commerce

What I get as a result:

  1. Varnish cache is shown as running (after I check with systemctl status varnish)
  2. Magento store is running fine (both frontend and admin panel are accessible)
  3. Headers are not showing X-Varnish or X-Magento-Cache or anything different before the operation was executed

Attached you may find the result I get from curl -I -v --location-trusted mywebsite.com enter image description here I did not change the .vcl file that Magento exports (should I?)

If you need any more information I am glad to provide. Please excuse my incompetence if there's any (I am an amateur in this whole process)

  • Typically you use Varnish behind a TLS terminator (NGINX, Hitch), but it appears you use none Mar 17 at 15:11
  • Isn't NGINX an alternative and vice verse to Apache or i am wrong?
    – rt89
    Mar 17 at 15:34
  • It is both alternative and can be used with Apache. Often times you use NGINX just to do TLS, then it forwards requests to Varnish, which forwards requests to Apache (OR another NGINX instance). The de-facto standard stack for Magento is probably NGINX TLS + Varnish + NGINX with PHP-FPM, but NGINX TLS + Varnish + Apache with mod_php is perfectly valid Mar 21 at 14:24

1 Answer 1


1. Run varnishlog to verify if transactions pass through Varnish

The first step is to run a targeted varnishlog command to verify whether traffic is actually going through Vanrish.

I'd recommend not using the homepage, because Varnish's local health checks my use that path.

Pick an existing page on the site, for example /test (replace with an actual page that exists) and run the following command on your Varnish server:

sudo varnishlog -g request -q "ReqUrl eq '/test'" 

But again: replace '/test' and the command with the actual page you're monitoring. Once the command is running and monitoring log transactions, go to the web page in your browser and verify whether varnishlog is showing output.

If not, Varnish is not being used.

2. Check the varnishd port in systemd

Out of the box, the varnishd runtime listens on port 6081 to avoid clashing with other web services.

Verify the port using the following command:

sudo systemctl cat varnish

This will print the full varnishd command with all its parameters. Look out for the -a parameter, which sets the listening port.

3. Check the listening port using lsof

Alternatively, run the following lsof command to figure out what service is running on port 80 (the conventional HTTP port):

sudo lsof -nP -iTCP:80 -sTCP:LISTEN

If the command is not varnishd, some other service is using the HTTP port.

4. Next steps

If varnishlog does display the right information, this means Varnish is correctly processing requests. In that case I suggest you check your VCL file to see if the relevant headers are stripped off in VCL.

If Varnish doesn't run on port 80, you'll have to run sudo systemctl edit --full varnish to modify the running port. When you're done run sudo systemctl restart varnish to make these changes go live.

The other service running port 80 needs to be reconfigured though, otherwise you'll have port clashes.

  • First of all, thank you very much for your reply. I followed all the steps and go to even last (my bad luck varnish was not working) - I edited and changed the port from 6081 to 80 - restarted the varnish - and repeated step 1 but still no logs were shown. :(
    – rt89
    Mar 18 at 18:09
  • @rt89 If you run sudo ps aux | grep varnish, do you see Varnish running on port 80 (-a :80)? Please check if the right response headers show up or run a more relaxed and general sudo varnishlog command without filters to see if anything is coming through. Mar 19 at 13:34
  • It shows a - 80
    – rt89
    Mar 19 at 18:43
  • 'sudo varnishlog' show me long list of rows - in many of them I found my website to be mentioned, images, URLs and logo and etc. Also show from which browser I loaded it - is that ok - what exactly should I looking for?
    – rt89
    Mar 19 at 18:55
  • @rt89 the fact that varnishlog is showing things, means that Varnish is being used. So I guess you've solved the issue. If you want to learn more about inspecting traffic with varnishlog, have a look at the following tutorial I wrote: varnish-software.com/developers/tutorials/varnishlog Mar 20 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.