I'm serving my WordPress on a subfolder of a node.js app.
My WordPress URL looks like
Everything runs well except when I try to set the fast_cgi_cache.
Here is my configuration:
location @blog {
rewrite ^/blog/(.*) /blog/index.php?q=$1;
}
location ^~ /blog {
alias /var/www/blog;
index index.php;
try_files $uri @blog;
# Caching
set $skip_cache 0;
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/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)") {
set $skip_cache 1;
}
#end Caching
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php7-fpm-sock;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_split_path_info ^/blog(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_cache WORDPRESS;
fastcgi_cache_bypass 1;
fastcgi_no_cache 1;
fastcgi_cache_valid 200 301 302 60m;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
add_header X-FastCGI-Cache $skip_cache;
}
}
Now when I log in and visit a page like:
I get an error:
/var/www/blog/2020/14/some-slug/index.php
doesn't exist.
This happens only when I'm logged in. i.e This test is true:
$http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in"
How can I fix this issue and can you please explain why it's happening? Thank you.