Skip to content

very confused about Varnish. Is it running or not? no headers it only says Pregma: cache

Maybe someone can help:

on Ubuntu, nginx, latest magento (2.4.6), varnish 6

This is my Nginx conf setup:

upstream varnish {
   ip_hash;
   server 127.0.0.1:6081;
   keepalive 32;
}

server {

    listen 443 ssl http2;
    server_name example.com www.example.com;

   ssl_certificate      /etc/letsencrypt/live/example.com/fullchain.pem;
   ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;

    #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 24h;
    keepalive_timeout 300s;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;

    # HSTS (ngx_http_headers_module is required) (63072000 seconds)
    add_header Strict-Transport-Security "max-age=63072000" always;
    location / {
        proxy_pass http://varnish;
        proxy_buffering off;
        proxy_request_buffering off;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Host $host;
        access_log off;
        log_not_found off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        client_max_body_size 32M; 
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header Ssl-Offloaded "1";
        proxy_read_timeout 600s;
}

This is my varnish /etc/varnish/default.vcl

backend default {
    .host = "127.0.0.1";
    .port = "6081";
    .first_byte_timeout = 600s;
    .probe = {
        .url = "/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}
sub vcl_deliver {
    if (resp.http.x-varnish ~ " ") {
        set resp.http.X-Magento-Cache-Debug = "HIT";
        set resp.http.Grace = req.http.grace;
    } else {
        set resp.http.X-Magento-Cache-Debug = "MISS";
    }

    # Not letting browser to cache non-static files.
    if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
        set resp.http.Pragma = "no-cache";
        set resp.http.Expires = "-1";
        set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
    }

    if (!resp.http.X-Magento-Debug) {
        unset resp.http.Age;
    }
#    unset resp.http.X-Magento-Debug;
#    unset resp.http.X-Magento-Tags;
#    unset resp.http.X-Powered-By;
#    unset resp.http.Server;
#    unset resp.http.X-Varnish;
}

When I do curl -I https://example.com

HTTP/2 200 
server: nginx/1.18.0 (Ubuntu)
date: Tue, 08 Aug 2023 20:13:23 GMT
content-type: text/html; charset=UTF-8
content-length: 199266
vary: Accept-Encoding
set-cookie: PHPSESSID=gge00en22a0548v46nifalmcon; expires=Tue, 08 Aug 2023 21:13:22 GMT; Max-Age=3600; path=/; domain=example.com; secure; HttpOnly; SameSite=Lax
pragma: cache
cache-control: max-age=1209600, public, s-maxage=1209600
expires: Tue, 22 Aug 2023 20:13:22 GMT
x-magento-tags: store,cms_b,cat_c,cat_c_391,cat_c_393,cat_c_394,cat_c_395,cat_c_396,cat_c_397,cat_c_398,cms_p_50,cms_b_sexshop_cart_promotion,cms_b_ox-hotspot-sp-home-slider-01,cat_p_18447,cat_p,cat_p_18439,cat_p_18438,cat_p_18415,cat_p_18379,cat_p_18368,cat_p_15614,cat_p_15413,mfb_p_0,mfb_p_1,cms_b_sexshop2-footer-content-clean,cms_b_
x-magento-debug: 1

I am in developper mode and I do not see anything in my header saying my varnish is working!

What should I do?