Skip to content

Magento 2 varnish settings on apache2 vhost

I’m new to Magento and Varnish.
I have an Ubuntu24 on Vbox. Magento 2.4.7-p3 with sample data is up and running. Varnish is activated in Magento Backend. I’m using the standard magento optimized vcl from varnish.

I have set the standard vhost port to 8080
The shop is running on an own vhost on port 8085
Varnish is using the port 80

Purge seems to be working, I’m getting 200 purged

/etc/default/varnish:

DAEMON_OPTS="-a :80 
             -T localhost:8085 
             -f /etc/varnish/default.vcl 
             -S /etc/varnish/secret 
             -s malloc,2048m"

I have searched quite a lot, but haven’t found any particular setting for a different vhost and port. Maybe because it’s nothing different that a setup without vhost…?

/etc/varnish/default.vcl:

backend default {
    .host = "localhost";
    .port = "8085";
    .first_byte_timeout = 600s;
    .probe = {
        .url = "/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
    }
}

everything else is standard from https://www.varnish-software.com/developers/tutorials/configuring-varnish-magento/

Anyway, when I try to
curl -I -X GET http://localhost:8085

I see

200 OK
Pragma: cache
Cache-control: max-age..., public...
X-Magento-Tags: ...
X-Magento-debug: 1
content-security-poilcy-report-only: a lot of stuff...
X-content-type-options
x-xss-protection
x-frame-options
set-cookie:
vary:
transfer-encoding
content-type:

when I try to
curl -I -X GET http://localhost

200 OK
content-security-poilcy-report-only: a lot of stuff...
X-content-type-options
x-xss-protection
x-frame-options
vary:
content-type:
X-Magento-Cache-control: max-age..., public...
Age:
X-Magento-Cache-debug: MISS
Pragma: no-cache
expires:
cache-control: no-store, no-cache, must-revalidate, max-age
transfer-encoding

X-Magento-Cache-debug: MISS is definitely not good, and it doesn’t matter which site I’m trying.

Is -T correct in /etc/default/varnish? Is the port correct in /etc/varnish/default.vcl?
var/cache/ and var/page_cache/ are not empty as well.
What am I missing in order to make varnish work and show HIT when using curl -I -X GET?