2

i have configured varnish in magento 2.4.5. i am getting varnishlog command X-Magento-Cache-Debug: MISS. currently i am using apache server.

I have configure varnish in Magento 2.4.5. Backend configured as per the below Screenshot. https://i.imgur.com/j0Oj2UL.png

but in frontend not show "X-Magento-Cache-Debug:MISS/HIT".

https://i.imgur.com/6QMBU1o.png

i have checked in server log using the below command.i am getting the below response and get

X-Magento-Cache-Debug : MISS

sudo varnishlog

*   << Request  >> 66232
-   Begin          req 66231 rxreq
-   Timestamp      Start: 1685699104.524062 0.000000 0.000000
-   Timestamp      Req: 1685699104.524062 0.000000 0.000000
-   VCL_use        boot
-   ReqStart       127.0.0.1 51720 a0
-   ReqMethod      GET
-   ReqURL         /health_check.php
-   ReqProtocol    HTTP/1.1
-   ReqHeader      Host: localhost
-   ReqHeader      Connection: close
-   ReqHeader      X-Forwarded-For: 127.0.0.1
-   VCL_call       RECV
-   VCL_return     pass
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       PASS
-   VCL_return     fetch
-   Link           bereq 66233 pass
-   Timestamp      Fetch: 1685699104.524305 0.000242 0.000242
-   RespProtocol   HTTP/1.1
-   RespStatus     503
-   RespReason     Backend fetch failed
-   RespHeader     Date: Fri, 02 Jun 2023 09:45:04 GMT
-   RespHeader     Server: Varnish
-   RespHeader     content-type: text/html; charset=utf-8
-   RespHeader     Retry-After: 5
-   RespHeader     X-Varnish: 66232
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish (Varnish/6.6)
-   VCL_call       DELIVER
-   RespHeader     **X-Magento-Cache-Debug: MISS**
-   RespHeader     Pragma: no-cache
-   RespHeader     Expires: -1
-   RespHeader     Cache-Control: no-store, no-cache, must-revalidate, max-age=0
-   RespUnset      Age: 0
-   RespUnset      Server: Varnish
-   RespUnset      X-Varnish: 66232
-   RespUnset      Via: 1.1 varnish (Varnish/6.6)
-   VCL_return     deliver
-   Timestamp      Process: 1685699104.524348 0.000285 0.000043
-   Filters
-   RespHeader     Content-Length: 282
-   RespHeader     Connection: close
-   Timestamp      Resp: 1685699104.524431 0.000368 0.000082
-   ReqAcct        70 0 70 293 282 575
-   End

I have debug it /etc/varnish/default.vcl file and check "sub vcl_deliver". if condition resp.http.x-varnish not true that's why it will not Hit Varnish.

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;
    unset resp.http.Via;
    unset resp.http.Link;
}

we have configured Port on varnish.service file as per the below screenshot.

File Path : /etc/varnish/default.vcl

https://i.imgur.com/SdJ5Yeg.png

File Path : /etc/systemd/system/varnish.service

https://i.imgur.com/kasjhbh.png

i have run server the below command i am getting the below o/p in terminal.

sudo varnishlog -g raw -i backend_health

0 Backend_health - default Still sick -------- 0 5 10 0.000000 0.000000 "Open error 110 (Connection timed out)"
         0 Backend_health - default Still sick -------- 0 5 10 0.000000 0.000000 "Open error 110 (Connection timed out)"
         0 Backend_health - default Still sick -------- 0 5 10 0.000000 0.000000 "Open error 110 (Connection timed out)"
         0 Backend_health - default Still sick -------- 0 5 10 0.000000 0.000000 "Open error 110 (Connection timed out)"
         0 Backend_health - default Still sick -------- 0 5 10 0.000000 0.000000 "Open error 110 (Connection timed out)"

1 Answer 1

0

The fact that your health check is the only item in the logs probably means that regular requests aren't being sent to Varnish.

While varnishlog output in general is very useful, your log output didn't contain a lot of debuggable information.

If Varnish is not receiving any of the requests, we should look at how Varnish is configured. I advise you to add your systemd settings for the varnishd.service file, this will show in which IP/port varnishd is listening. It might explain why you're not seeing the logs in varnishlog and why the debug header is missing.

Let's start with that and work our way forward.

Update

The root cause of the problem is as expected: Varnish is not listening on port 80.

Your varnish.service file has varnishd listening in port 8080.

Here's the solution:

  • Stop varnishd and reconfigure varnish.service to listen on port 80 by setting -a :80
  • Stop your web server and make it listen on port 8080
  • Run sudo systemctl daemon-reload to make sure systemd is aware of the configure changes
  • Restart varnish by running sudo systemctl restart varnish
  • Restart your web server
  • Alter your Magento configuration for Varnish and set the backend on port 8080 if that is not the case
1
  • I have added varnish.service file and default.vcl file screenshot.please check Commented Jun 5, 2023 at 4:37

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.