2

I have Varnish configured in my server and my project is running in production mode, even though, I continue seeing the debug tag X-Magento-Cache-Debug in the header.

Magento 2 production mode

Magento 2 Varnish X-Magento-Cache-Debug

According to Devdocs - Varnish Final verification this header tag just show up in developer mode.

Why does it happen and how could I solve it? Thanks

2 Answers 2

4

The X-Magento-Cache-Debug header is set by Varnish VCL itself. From a standard VCL:

sub vcl_deliver {
    if (resp.http.X-Magento-Debug) {
        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";
        }
    } else {
        unset resp.http.Age;
    }
    # ....
    unset resp.http.X-Magento-Debug;
    # ...
}

So its inclusion is dictated by presence of the header X-Magento-Debug which is set by Magento code here:

            if ($this->state->getMode() == AppState::MODE_DEVELOPER) {
                $result->setHeader('X-Magento-Debug', 1);
            }

As you can decipher from the code above, Magento 2 sets theX-Magento-Debug header for Varnish when it's being run in developer mode.

"For Varnish" - taking note that few lines later (in VCL), the X-Magento-Debug is being unset and clients will only see the X-Magento-Cache-Debug header.

Subsequently, make sure that you're not dealing with the note from your own post:

Environment variables may override this value

Make sure that:

  • NGINX/Apache is setting production mode via an environment variable (as opposed to developer or default), e.g.: set $MAGE_MODE production; (NGINX)
  • You are using the standard VCL code
  • You have cleared PHP OPcache - potentially, you are running with validate_timestamps = Off, and the PHP-FPM pool is still running in developer mode until the cache is pruned.
3

I think it's normal if you're using Magento version >= 2.4.4. Because the code has changed in the varnish6.vcl.

Now the code is as the following:

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";
    }

Now X-Magento-Cache-Debug header is included in all deployment modes.

For more information: https://github.com/magento/magento2/blob/2.4.4/app/code/Magento/PageCache/etc/varnish6.vcl#L210

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.