Ipstenu / varnish-http-purge

Proxy Cache Purge
Apache License 2.0
46 stars 47 forks source link

Cache Service Varnish caching service is running but is unable to cache your site. #94

Closed dgaastra closed 1 year ago

dgaastra commented 3 years ago

Dear list,

We are running [SSL/443] -> hitch -> [socket] + [port 80] -> varnish -> [HTTP/8080] -> apache.

Caching appears to be working, however, we always get this error message in the plugin:

Cache Service Varnish caching service is running but is unable to cache your site.

How can this be resolved.

Ipstenu commented 3 years ago

That really should be "The plugin is unable to determine if your site is properly cached"

It means that the plugin isn't getting the return it expects from your site when it self checks. How are you confirming cache is working?

dgaastra commented 3 years ago

Hi Ipstenu,

thanks for looking into this and helping us out:

APACHE2 LOG

www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:37 +0200] "GET /wp-admin/admin.php?page=varnish-check-caching HTTP/1.1" 200 38343 227927 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:38 +0200] "GET /wp-json/fl-assistant/v1/batch?routes[]=%2Ffl-assistant%2Fv1%2Fcounts&routes[]=%2Ffl-assistant%2Fv1%2Flabels HTTP/1.1" 200 1616 179401 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:38 +0200] "POST /wp-json/fl-assistant/v1/current-user/state HTTP/1.1" 200 1756 193544 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:39 +0200] "POST /wp-admin/options.php HTTP/1.1" 302 1026 149179 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:40 +0200] "GET /wp-admin/admin.php?page=varnish-check-caching&settings-updated=true HTTP/1.1" 200 39617 1226151 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:41 +0200] "GET /wp-json/fl-assistant/v1/batch?routes[]=%2Ffl-assistant%2Fv1%2Fcounts&routes[]=%2Ffl-assistant%2Fv1%2Flabels HTTP/1.1" 200 1644 199305 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" www.example1.com MY.CL.IP.AD [25/Aug/2021:10:18:41 +0200] "POST /wp-json/fl-assistant/v1/current-user/state HTTP/1.1" 200 1718 191102 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15"

VARNISH LOG:

MY.CL.IP.AD - - [25/Aug/2021:10:18:05 +0200] "GET http://www.example1.com/ HTTP/2.0" 200 13416 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:05 +0200] "GET http://www.example1.com/wp-content/uploads/2021/04/xcropped-ISP_favicon512x512-32x32.png.pagespeed.ic.WsP5nm41FV.jpg HTTP/2.0" 200 830 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:06 +0200] "GET http://www.example1.com/ HTTP/2.0" 200 13416 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:06 +0200] "GET http://www.example1.com/wp-content/uploads/2021/04/xcropped-ISP_favicon512x512-32x32.png.pagespeed.ic.WsP5nm41FV.jpg HTTP/2.0" 200 830 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:06 +0200] "GET http://www.example1.com/ HTTP/2.0" 200 13416 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:07 +0200] "GET http://www.example1.com/wp-content/uploads/2021/04/xcropped-ISP_favicon512x512-32x32.png.pagespeed.ic.WsP5nm41FV.jpg HTTP/2.0" 200 830 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:29 +0200] "GET http://www.example1.com/ HTTP/2.0" 200 13416 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:29 +0200] "GET http://www.example1.com/wp-content/uploads/2021/04/xcropped-ISP_favicon512x512-32x32.png.pagespeed.ic.WsP5nm41FV.jpg HTTP/2.0" 200 830 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:30 +0200] "GET http://www.example1.com/ HTTP/2.0" 200 13416 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:30 +0200] "GET http://www.example1.com/wp-content/uploads/2021/04/xcropped-ISP_favicon512x512-32x32.png.pagespeed.ic.WsP5nm41FV.jpg HTTP/2.0" 200 830 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:31 +0200] "GET http://www.example1.com/ HTTP/2.0" 200 13416 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:32 +0200] "GET http://www.example1.com/wp-content/uploads/2021/04/xcropped-ISP_favicon512x512-32x32.png.pagespeed.ic.WsP5nm41FV.jpg HTTP/2.0" 200 830 "https://www.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" MY.CL.IP.AD - - [25/Aug/2021:10:18:37 +0200] "GET http://www.example1.com/wp-admin/admin.php?page=varnish-check-caching HTTP/2.0" 200 37344 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" MY.CL.IP.AD - - [25/Aug/2021:10:18:38 +0200] "GET http://www.example1.com/wp-json/fl-assistant/v1/batch?routes[]=%2Ffl-assistant%2Fv1%2Fcounts&routes[]=%2Ffl-assistant%2Fv1%2Flabels HTTP/2.0" 200 392 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" MY.CL.IP.AD - - [25/Aug/2021:10:18:38 +0200] "POST http://www.example1.com/wp-json/fl-assistant/v1/current-user/state HTTP/2.0" 200 316 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" MY.CL.IP.AD - - [25/Aug/2021:10:18:39 +0200] "POST http://www.example1.com/wp-admin/options.php HTTP/2.0" 302 0 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" 127.0.0.1 - - [25/Aug/2021:10:18:40 +0200] "GET http://www.example1.com/ HTTP/1.1" 301 0 "http://www.example1.com/" "WordPress/5.8; https://www.example1.com" 127.0.0.1 - - [25/Aug/2021:10:18:40 +0200] "GET http://www.example1.com/ HTTP/1.1" 200 60760 "https://www.example1.com/" "WordPress/5.8; https://www.example1.com" 127.0.0.1 - - [25/Aug/2021:10:18:41 +0200] "GET http://www.example1.com/ HTTP/1.1" 301 0 "http://www.example1.com/" "WordPress/5.8; https://www.example1.com" 127.0.0.1 - - [25/Aug/2021:10:18:41 +0200] "GET http://www.example1.com/ HTTP/1.1" 200 60760 "https://www.example1.com/" "WordPress/5.8; https://www.example1.com" MY.CL.IP.AD - - [25/Aug/2021:10:18:40 +0200] "GET http://www.example1.com/wp-admin/admin.php?page=varnish-check-caching&settings-updated=true HTTP/2.0" 200 38656 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" MY.CL.IP.AD - - [25/Aug/2021:10:18:41 +0200] "GET http://www.example1.com/wp-json/fl-assistant/v1/batch?routes[]=%2Ffl-assistant%2Fv1%2Fcounts&routes[]=%2Ffl-assistant%2Fv1%2Flabels HTTP/2.0" 200 392 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" MY.CL.IP.AD - - [25/Aug/2021:10:18:41 +0200] "POST http://www.example1.com/wp-json/fl-assistant/v1/current-user/state HTTP/2.0" 200 316 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" MY.CL.IP.AD - - [25/Aug/2021:10:19:41 +0200] "POST http://www.example1.com/wp-admin/admin-ajax.php HTTP/2.0" 200 67 "https://www.example1.com/wp-admin/admin.php?page=varnish-check-caching" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15"

Ipstenu commented 3 years ago

If you run curl -I http://www.example1.com what kind of response do you get?

Just as an example, on one site I use, I get this:

x-cacheable: YES
cache-control: must-revalidate, public, max-age=300, stale-while-revalidate=360, stale-if-error=43200
vary: Accept-Encoding
x-varnish: 2391648 4128646
age: 1763
via: 1.1 varnish (Varnish/6.5)
x-cache: HIT
x-powered-by: DreamPress
accept-ranges: bytes
strict-transport-security: max-age=15768000

If you're not getting that x-cacheable and x-cache, then the return from the plugin will always say that it's not caching.

dgaastra commented 3 years ago

HI there,

running on local server, contacting varnish at port 80, we get a redirect:

:~$ curl -I http://www.example1.com HTTP/1.1 301 Moved Permanently Date: Thu, 26 Aug 2021 07:02:08 GMT Server: Apache X-Redirect-By: WordPress Strict-Transport-Security: max-age=63072000; includeSubDomains; preload Location: https://www.example1.com/ Cache-Control: max-age=2592000, s-maxage=10 Expires: Sat, 25 Sep 2021 07:02:08 GMT X-Content-Type-Options: nosniff X-Frame-Options: sameorigin Content-Security-Policy: ...; X-XSS-Protection: 1; mode=block Vary: X-Forwarded-Proto Content-Length: 0 Content-Type: text/html; charset=UTF-8 X-Varnish: 131472 Age: 0 Via: 1.1 varnish (Varnish/6.1) Connection: keep-alive

Ipstenu commented 3 years ago

Well yeah, that's why.

  1. HTTP/1.1 301 Moved Permanently -- that's gonna throw an error
  2. Age: 0 - If the age is ZERO it wasn't cached.

I bet if you solve the 301 error then it'll be fixed. Likely you have a mismatch with your home and site URLs and the one you're actually using...

Actually I KNOW you do.

You curled HTTP right?

But look at what came back:

Location: https://www.example1.com/

So the plugin (properly) is saying "Hey, http domain is not cached, because it's going to https"

Fix that :) You should be right as rain.

dgaastra commented 3 years ago

HI Ipstenu,

Sorry for the delay, I was on holidays for 2 weeks. Just looked into this - even when curling Apache directly at port 8080, the message is still the same.

As far as I understand, it is Wordpress that performs the redirect based on WP_HOME and WP_SITEURL because they contain https. So how should Worpress be configured to make things work?

currently: define('WP_HOME' ,'https://www.example1.com'); define('WP_SITEURL','https://www.example1.com');

Thanks

Dennis

Ipstenu commented 3 years ago

Looking at all that ... I think your hitch proxy isn't set up correctly. Now, sadly, that's outside my area of knowledge (we use nginx proxy, it did slightly better on our tests and was more performant in other ways that were outside Varnish, so we didn't want nginx AND hitch).

As far as I understand, it is Wordpress that performs the redirect based on WP_HOME and WP_SITEURL because they contain https.

Actually no. WP doesn't redirect. You would have that setup on your server (apache config) or on your account (.htaccess). You could do it with a plugin of course.

$ curl -I https://www.example1.com

and

$ curl -I http://www.example1.com

will give different results, but honestly, even with https as a redirect, I get both http and https cached, so that you're not suggests it's a server setup issue :(

dgaastra commented 3 years ago

HI Ipstenu:

Thanks for your response, but I am not quite sure:

Maybe you can point us in the right direction. Thanks.

Dennis

Ipstenu commented 3 years ago

$ curl -I http://www.example1.com goes to port 80 from Varnish and provides the known "X-Redirect-By: WordPress".

That's not default WordPress, though. For real, it's just not. You've got 'something' on your site that tells WP to redirect, but out of the box it doesn't redirect http to https. You have to set up something to do it.

We ignore .htaccess files and our apache configurations do not have any rewrites other than Wordpress':

Then you have something inside WordPress to rewrite/redirect, but again, it's not core WordPress.

The fact that your http URL redirects and is not cached is 100% something on your end.

Here's an example of a site that is on WordPress and Varnish (with an NGINX proxy). It uses Apache to redirect http -> https.

--- ~/Downloads » curl -I http://plugintest.breakwpdh.com
HTTP/1.1 301 Moved Permanently
Date: Mon, 13 Sep 2021 23:08:20 GMT
Server: Apache
Location: https://plugintest.breakwpdh.com/
Content-Type: text/html; charset=iso-8859-1
X-Cacheable: YES:Forced
Cache-Control: must-revalidate, public, max-age=300, stale-while-revalidate=360, stale-if-error=43200
Vary: Accept-Encoding
X-Varnish: 203088 14430
Age: 3395
Via: 1.1 varnish (Varnish/6.5)
X-Cache: HIT
X-Powered-By: DreamPress
Content-Length: 241
Connection: keep-alive

--- ~/Downloads » curl -I https://plugintest.breakwpdh.com
HTTP/2 200
date: Tue, 14 Sep 2021 00:05:01 GMT
content-type: text/html; charset=UTF-8
content-length: 24603
server: Apache
link: <https://plugintest.breakwpdh.com/wp-json/>; rel="https://api.w.org/"
x-cacheable: YES:Forced
cache-control: must-revalidate, public, max-age=300, stale-while-revalidate=360, stale-if-error=43200
vary: Accept-Encoding
x-varnish: 203090 203037
age: 2666
via: 1.1 varnish (Varnish/6.5)
x-cache: HIT
x-powered-by: DreamPress
accept-ranges: bytes
strict-transport-security: max-age=15768000

See how both are cached? Now if I disable the htaccess redirect:

--- ~/Downloads » curl -I http://plugintest.breakwpdh.com                                                                                   7 ↵
HTTP/1.1 200 OK
Date: Tue, 14 Sep 2021 00:07:11 GMT
Server: Apache
Link: <https://plugintest.breakwpdh.com/wp-json/>; rel="https://api.w.org/"
Content-Type: text/html; charset=UTF-8
X-Cacheable: YES:Forced
Cache-Control: must-revalidate, public, max-age=300, stale-while-revalidate=360, stale-if-error=43200
Vary: Accept-Encoding
X-Varnish: 2
Age: 0
Via: 1.1 varnish (Varnish/6.5)
X-Cache: MISS
X-Powered-By: DreamPress
Accept-Ranges: bytes
Content-Length: 24593
Connection: keep-alive

--- ~/Downloads » curl -I http://plugintest.breakwpdh.com
HTTP/1.1 200 OK
Date: Tue, 14 Sep 2021 00:07:11 GMT
Server: Apache
Link: <https://plugintest.breakwpdh.com/wp-json/>; rel="https://api.w.org/"
Content-Type: text/html; charset=UTF-8
X-Cacheable: YES:Forced
Cache-Control: must-revalidate, public, max-age=300, stale-while-revalidate=360, stale-if-error=43200
Vary: Accept-Encoding
X-Varnish: 32773 3
Age: 75
Via: 1.1 varnish (Varnish/6.5)
X-Cache: HIT
X-Powered-By: DreamPress
Accept-Ranges: bytes
Content-Length: 24593
Connection: keep-alive

I ran it twice so you could see there's no 'redirected by WordPress' on a standard install but also that, in fact, it is caching. Which tells me your setup doesn't understand how to cache the http side, which is 100% something to do on your end. I'm really sorry about that one, I cannot help.

Now. All of that said, we're back to the beginning of "Why is the PLUGIN not able to detect the cache?"

At a best guess at this point, your WP site isn't actually on https. You mention you have the home/site URLs defined in WP config. Check the URls in wp-admin -- Make 100% sure they're correct. If you're using home and site URLs as defines, then that suggests an abnormal setup, but you haven't mentioned anything about that, so I'm grasping at straws.

My advice is that if the https is properly cached, don't worry about the plugin's checker.

dgaastra commented 3 years ago

HI Mika,

Thanks for your response. It is important for us that your plugin works with our configurations as we have many sites now changed over to use Varnish+Hitch. So I really wanna get to the bottom of this and prefer your plugin to be 'happy'.


admin@web1:~$ curl -I http://www.example1.com:8080
HTTP/1.1 301 Moved Permanently
Date: Tue, 14 Sep 2021 14:13:51 GMT
Server: Apache
X-Redirect-By: WordPress
DEBUG: #0 wp-includes/canonical.php(799): wp_redirect() #1 wp-includes/class-wp-hook.php(303): redirect_canonical() #2 wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #3 wp-includes/plugin.php(470): WP_Hook->do_action()    #4 wp-includes/template-loader.php(13): do_action() #5 wp-blog-header.php(19): require_once('/www/example...')  #6 index.php(17): require('/www/example...')    #7 {main}
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
Upgrade: h2,h2c
Connection: Upgrade
Location: https://www.example1.com/
Cache-Control: max-age=2592000
Expires: Thu, 14 Oct 2021 14:13:51 GMT
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
Content-Security-Policy: ...
X-XSS-Protection: 1; mode=block
Vary: X-Forwarded-Proto
Content-Type: text/html; charset=UTF-8

Which appears to be core Wordpress?!?

  • [5] Varnish contacts Apache at 8080 with http - without SSL. Using the excellent VCL from Thijs Feryn, it should be noted that a req.http.X-Forwarded-Proto = "https" is set:

    # Add X-Forwarded-Proto header when using https
    if (!req.http.X-Forwarded-Proto && (std.port(server.ip) == 443)) {
        set req.http.X-Forwarded-Proto = "https";
    }
dgaastra commented 3 years ago

Hi Mika,

Decided to forget about redirects since these are not shown in your plugin "Technical Details", and performed a reverse analysis on your plugins' debug code and concluded that it needs "X-Cacheable" to be set, which is currently not in the headers. All URLs provide the following:


x_varnish = true
x_date = true
x_age = true
x_cachable = false
x_age_vapc = true
x_via = true
x_cache = false
x_p_cache = false
cacheheaders_set = true
is_cachable = true
cache_service = true
still_cachable = false

in debug.php


                        // Get some basic truthy/falsy from the headers.
                        // Headers used by both.
                        $x_varnish = ( isset( $headers['X-Varnish'] ) ) ? true : false;
                        $x_date    = ( isset( $headers['Date'] ) && strtotime( $headers['Date'] ) !== false ) ? true : false;
                        $x_age     = ( isset( $headers['Age'] ) ) ? true : false;
echo "x_varnish = " . ($x_varnish ? 'true' : 'false' ) . "
"; echo "x_date = " . ($x_date ? 'true' : 'false' ) . "
"; echo "x_age = " . ($x_age ? 'true' : 'false' ) . "
"; // Is this Nginx or not? $x_nginx = ( isset( $headers['server'] ) && ( strpos( $headers['server'], 'nginx' ) !== false || strpos( $headers['server'], 'openresty' ) !== false ) ) ? true : false; // Headers used by Nginx. $x_varn_hit = ( $x_varnish && strpos( $headers['X-Varnish'], 'HIT' ) !== false ) ? true : false; $x_age_nginx = ( $x_varn_hit || ( $x_age && $x_date && ( strtotime( $headers['Age'] ) < strtotime( $headers['Date'] ) ) ) ) ? true : false; $x_pragma = ( ! isset( $headers['Pragma'] ) || ( isset( $headers['Pragma'] ) && strpos( $headers['Pragma'], 'no-cache' ) === false ) ) ? true : false; // Headers used ONLY by Apache/Varnish. $x_cachable = ( isset( $headers['X-Cacheable'] ) && strpos( $headers['X-Cacheable'], 'YES' ) !== false ) ? true : false; $x_age_vapc = ( $x_age && $headers['Age'] > 0 ) ? true : false; echo "x_cachable = ". ($x_cachable ? 'true' : 'false' ) . "
"; echo "x_age_vapc = ". ($x_age_vapc ? 'true' : 'false' ) . "
"; //makes warning go away $x_cachable = true; // Optional Headers. $x_via = ( is_numeric( strpos( $headers['Via'], 'arnish' ) ) ) ? true : false; $x_cache = ( isset( $headers['x-cache-status'] ) && strpos( $headers['x-cache-status'], 'HIT' ) !== false ) ? true : false; $x_p_cache = ( isset( $headers['X-Proxy-Cache'] ) && strpos( $headers['X-Proxy-Cache'], 'HIT' ) !== false ) ? true : false; echo "x_via = " . ($x_via ? 'true' : 'false' ) . "
"; echo "x_cache = " . ($x_cache ? 'true' : 'false' ) . "
"; echo "x_p_cache = " . ($x_p_cache ? 'true' : 'false' ) . "
"; // Are cache HEADERS set? $cacheheaders_set = ( isset( $headers['X-Cacheable'] ) || $x_varnish || isset( $headers['X-Cache'] ) || $x_via ) ? true : false; echo "cacheheaders_set = " . ($cacheheaders_set ? 'true' : 'false' ) . "
"; // Is Cacheable? $is_cachable = ( $x_varnish && $x_age ) ? true : false; $still_cachable = true; echo "is_cachable = " . ($is_cachable ? 'true' : 'false' ) . "
";

Question: What is your opinion? Thanks. Dennis

Ipstenu commented 3 years ago

There's a lot to unpack here.

Do you NEED x-Cachable? Well it's used by us because a number of managed WordPress hosts already used it and it was a quick check for some hosts that don't have all the details. Also we've found it very helpful in debugging when users do weird things.

Try setting it, see if it works. If it does, then yes. But frankly, I still think you've done something in yourself with X-Redirect since WP doesn't know that one in the manner you're running it.

Also, you keep saying you set the home and site url in the config file.

Did you perhaps set them as HTTP and not HTTPS? I personally would delete those lines and see if it magically works. It's possible they're messing with redirects.

dgaastra commented 3 years ago

Hi Mika,

Hope your Yom Kippur went well. Thanks for getting back here. Like shown above, your plugin works if $x_cachable is rigged; and, as such, I am confident that with Thijs' newest code, your plugin will be happy. Will test over the next couple of days here.

About the Wordpress redirects, scroll up a few posts, you'll see the definitions correctly: define('WP_HOME' ,'https://www.example1.com'); and define('WP_SITEURL','https://www.example1.com'); We do this for hundreds of websites to have a lower TTFB...always with "https://" and "www.".

Interestingly, curling on a main hosting server:

curl -I https://www.example1.com/firstpage/         -> 200 OK
curl -I http://www.example1.com/firstpage/          -> 200 OK
curl -I http://www.example1.com:8080/firstpage/     -> 301 Moved Permanently :: Location: http://www.example1.com/firstpage/ (NOTE: http)
curl -I http://www.example1.com:80/firstpage/           -> 200 OK

curl -I https://www.example1.com/               -> 200 OK
curl -I http://www.example1.com/                -> 301 Moved Permanently :: Location: https://www.example1.com/
curl -I http://www.example1.com:8080                -> 301 Moved Permanently :: Location: https://www.example1.com/
curl -I http://www.example1.com:80              -> 301 Moved Permanently :: Location: https://www.example1.com/

I don't know if this is still relevant.

Best regards,

Dennis

Ipstenu commented 3 years ago

It may be and I'll dig into it more again.

Honestly I have seen some VERY weird behaviour when people hardcoded in the siteurl and home (backup plugins just ... stop working) and it all ran back down to 'something' about the command line (which basically Varnish is doing) isn't 'seeing' the URL. So while WP is happy as a clam, the server is confused.