We've followed these instructions https://support.plesk.com/hc/en-us/articles/115001888894-Does-Plesk-support-Varnish- and were able to get it to work 'properly', it serves the wordpress site through varnish and the speed is amazing. All good and well, but our uptime robot reports short downtime every now and then (very irregular, but between 1 and 8 times a day for a period of <5 minutes, on various times throughout the day).
After some various testing we've noticed an issue with the wp-admin url, we've concluded that this occurs because of our DirectoryIndex (which is index.html by default), we've resolved this by adding 'DirectoryIndex index.php' to our 'Additional Apache directives' which resolved that issue.
One thing that seemed interesting to us is that when we change how PHP(FPM) is served, it affects the same error. When we serve through NGINX we'll get err_too_many_redirects aswell, if we serve it through Apache it works 95% of the time.
I've added some (varnishncsa) logging below, when the header response states 301 that's when we're in the loop:
172.17.0.1 - - [11/Jan/2022:13:54:55 +0000] "HEAD http://[the varnish domain]/ HTTP/1.0" 200 0 "https://[the varnish domain]" "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.[uptimerobot].com/)"
172.17.0.1 - - [11/Jan/2022:13:56:51 +0000] "GET http://[the varnish domain]/ HTTP/1.0" 200 11184 "-" "-"
172.17.0.1 - - [11/Jan/2022:13:58:31 +0000] "HEAD http://[the varnish domain]/ HTTP/1.0" 301 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36"
172.17.0.1 - - [11/Jan/2022:13:58:32 +0000] "HEAD http://[the varnish domain]/ HTTP/1.0" 301 0 "http://[the varnish domain]" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36"
After this we the following log 8 times:
172.17.0.1 - - [11/Jan/2022:13:58:32 +0000] "HEAD http://[the varnish domain]/ HTTP/1.0" 301 0 "https://[the varnish domain]/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36"
Then one:
172.17.0.1 - - [11/Jan/2022:13:58:34 +0000] "GET http://[the varnish domain]/ HTTP/1.0" 301 238 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/96.0.4664.110 Safari/537.36"
Then 7 times:
172.17.0.1 - - [11/Jan/2022:13:59:55 +0000] "HEAD http://[the varnish domain]/ HTTP/1.0" 301 0 "https://[the varnish domain]" "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.[uptimerobot].com/)"
Then 22 times:
172.17.0.1 - - [11/Jan/2022:14:00:17 +0000] "GET http://[the varnish domain]/ HTTP/1.0" 301 238 "https://[the varnish domain]" "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.[uptimerobot].com/)"
Then right after that everything seems fine again.
Update: inspecting the logs
@thijs-feryn pointed out something interesting, which made us conclude that we've dismissed an older theory too soon.Since we felt sure that X-Forwarded-Proto was passed on, because it was in our 'additional apache header configuration'.
However after reading his response carefully we've learned that somehow X-Forwarded-Proto doesn't get passed every request (atleast not on the broken ones). He pointed out that [another varnish domain] seemed to pass this record just fine in a similar request.
After some carefull comparing of the configurations only one thing stood out to us, which was that the preffered domain in plesk for [another varnish domain] was set to 'None', and for [the varnish domain] is was set to [the varnish domain].
So we went to www.[the varnish domain] in our browser, and that seemed to trigger the issue. We switched 'Preferred domain' to 'None' here aswell and now www.[the varnish domain] redirects to [the varnish domain] just fine.
hypothesis
It seems that plesk's own redirect ignores the 'Additional directives for HTTP' and thus 'Vary: X-Forwarded-Proto' wasn't added. We'll be monitoring this and we'll post an update soon, when we're fully confident that this was the cause.