How to exclude certain files from fastcgi cache with regular expression

24 Views Asked by At

How can I exclude certain files from the fastcgi cache in Nginx using regex? I have tried a location block and a map, can't get either to work.

I have fastcgi settings in a location block for php files, here's a simplified version of it:

location ~ [^/]\.php(/|$) {
    fastcgi_no_cache $skip_cache;
    fastcgi_cache_bypass $skip_cache;
}

Above that I tried to set exclusions with the $skip_cache variable in another location block:

# match certain files ending with .php
location \/(reports|purge|renewalemail|renewalcriteria)\.php$ {
    set $skip_cache 1;
}

I also tried this outside the server block:

map $request_uri $skip_cache {
    # Enable caching in general
    default 0;
    # disable it for these URLs
    "/log/" 1;
    # use regular expressions
    "\/(reports|purge|renewalemail|renewalcriteria)\.php$" 1;
}

But the files continue to get cached. What am I doing wrong? Thanks for any help.

0

There are 0 best solutions below