magento2: Varnish does not appear to be configured for a public folder web root (at least, with NGINX)

Preconditions

  1. Magento 2.4-develop
  2. Varnish 4/5/6

Steps to reproduce

  1. Set up a server according to the provided recommendations, with NGINX as the HTTP host and using the public folder
  2. Export varnish as shown by Magento
  3. Install varnish configuration

Expected result

  1. Server works

Actual result

  1. Varnish doesn’t work (specifically, it returns a 503 and complains about upstream being down). Additionally, there are a bunch of messages in the NGINX error log about “404 /pub/health_check.php not found”

File is here: https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/PageCache/etc/varnish5.vcl

As you can see, it has the pub hardcoded. I might suggest doing detection in the application, and adjusting the probe root accordingly.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (12 by maintainers)

Most upvoted comments

How is this still open after multiple years? Or maybe we’re all expected to investigate the exported VCL file and catch the error ourselves?

This is still an issue.

Preconditions

  • Magento 2.3.1
  • Varnish 4
  • Run Magento out of pub (web root being pub — the proper way to run PHP apps)

Steps to reproduce

  • Click Export VCL for Varnish 4

Expected result

  • Nothing breaks

Actual result

  • Website down because health check URLs have pub in them for whatever reason

Specifically the following lines:

Line 12: .url = "/pub/health_check.php"; (why is /pub there? of course backend origin is going to 404, making Varnish think that the node is down…)

Line 65:

# Bypass health check requests
if (req.url ~ "/pub/health_check.php") {
    return (pass);
}

@rou9e Thanks that helped! Got probe working now instead of removing it! 👍

There is some point that need to be fixed also in 2.4

  1. If you Change /pub/health_check.php to health_check.php in probe section of backend i suppose you also need to change the bypass section also, or varnish will cache result of first check
# Bypass health check requests
    if (req.url ~ "/health_check.php") {
        return (pass);
    }
  1. My varnish still unable to check the file also if i can curl it from the varnish host, also after reboot of magento web server, varnish and proxy.
sudo varnishlog -g raw -i backend_health
         0 Backend_health - default Still sick 4---X-R- 0 5 10 0.002558 0.000000 HTTP/1.1 404 Not Found
         0 Backend_health - default Still sick 4---X-R- 0 5 10 0.002298 0.000000 HTTP/1.1 404 Not Found 
curl -i https://magento2/health_check.php
HTTP/2 200 

Also magento webserver log show this that has no sense for me:

10.132.0.19 - - [24/Mar/2021:11:45:11 +0000] "GET /health_check.php HTTP/1.1" 404 162 "-" "-"
10.132.0.19 - - [24/Mar/2021:11:45:16 +0000] "GET /health_check.php HTTP/1.1" 404 162 "-" "-"
10.132.0.9 - - [24/Mar/2021:11:45:19 +0000] "GET /health_check.php HTTP/1.0" 200 12 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/xxx Safari/537.36"

varnish server is the only one getting 404 result

Any idea? Restarterd fpm and nginx. I can reach the page with a browser and get a 200 status

@andrewhowdencom, thank you for your report. We’ve created internal ticket(s) MAGETWO-83718 to track progress on the issue.