Help set up a WordPress bypass with a static cache

You’re right, I tried both these solutions and none worked, exactly for the reason you explained.

Using the solution given by @francislavoie, it seems to work though. :+1:

I will wait and see for a couple of days, but if I can confirm it works fine, I will open a Wiki for this special edge case. It’s really a proof of the strength of Caddy 2, compared to Caddy 1 or even the other webservers out there.

So, thanks again, @matt :slight_smile:

3 Likes

Excellent, please do share your final results with us!

1 Like

Gladly, let me know if there is something useless here. I have already removed the php_fastcgi from the cache route, I guessed it was not necessary and indeed, it works fine without.

(static) {
	@static {
		file
		path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.json
	}
	header @static Cache-Control max-age=5184000
}

(security) {
	header {
		# enable HSTS
		Strict-Transport-Security max-age=31536000;
		# disable clients from sniffing the media type
		X-Content-Type-Options nosniff
		# keep referrer data off of HTTP connections
		Referrer-Policy no-referrer-when-downgrade
	}
}

voiretmanger.fr {
	root * /var/www/voiretmanger.fr
	encode zstd gzip
	file_server
	import static
	import security
	log {
		output file /var/log/caddy/voiretmanger.fr.access.log
	}

	# Redirect personnels
	redir /a-propos/publicite /soutien
	redir /archives/carte-des-restaurants /a-manger

	@cache {
		not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
		not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
		not method POST
		not expression {query} != ''
    }

    route @cache {
        try_files /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
    }
        
    php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
}

Is there something else I should reorganise/get rid of/change ?

2 Likes

Your Caddyfile looks pretty clean, I don’t really have anything to suggest :+1:

Maintenant je peux allez me coucher avec satisfaction. C’était une question truquée.

2 Likes

Encore merci, et désolé. :slight_smile:

Bonne nuit !

1 Like

Strictly speaking I think this should be

(not header) && (not path) && (not method) && (not expression)

I think your alternative is just the inverse of the inverse. To match that logic expression (a bunch of OR’d NOTs), any path that’s missing any of them would pass (i.e. only the presence of all of them would constitute a failure to match), whereas AND’d NOTs would fail out if any single one of them were present, which is the desired result and matches the functionality of the actual matcher you specified immediately after.

Logic, man!

2 Likes

Yeah you’re completely right. My brain is fried. But at least it I was able to come up with the proper matcher :man_shrugging:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.