NGINX fastcgi_cache

masterfork

New member
Joined
Jul 20, 2020
Messages
1
Hi - apologies for the repost but I realized this section is probably more suited to my question:

Essentially, I set up a new CentOs 7 server and installed directadmin as I normally would. I restored a backup on apache, and then decided I want to switch over completely to NGINX. Things are up and running, but I cannot seem to modify the right config files to get caching enabled. One of the things that's telling me I'm doing something wrong is that none of the add_header I'm inserting do anything (regardless where they are).

What I'm doing now: I edited the nginx.conf in /etc/nginx to include:
Code:
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=phpcache:100m max_size=10g inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

And then for the domain in question, I did custom HTTPD in CUSTOM3 with the following:
Code:
set $skip_cache 0;

# 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-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") {
    set $skip_cache 1;
}

# 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;
}
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_ignore_headers "Set-Cookie";
fastcgi_hide_header "Set-Cookie";
    location / {
add_header XSDFSDF-Cache $upstream_cache_status;
        try_files $uri $uri/ /index.php?$args;
}
    location ~ \.php$ {
fastcgi_cache phpcache;
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;
add_header X-FastCGI-Cache $upstream_cache_status;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
}

Anyone have any ideas on how this could work?

Thanks!
 
Back
Top