FRiCKLE / ngx_cache_purge

nginx module which adds ability to purge content from FastCGI, proxy, SCGI and uWSGI caches.
http://labs.frickle.com/nginx_ngx_cache_purge/
Other
1.06k stars 311 forks source link

Keys with trailing slashes are not being deleted #37

Open doliver3 opened 9 years ago

doliver3 commented 9 years ago

Hi,

Keys with trailing slashes are not being deleted.

I've compiled with the latest nginx and this codebase as of 2 days ago. Our wordpress site always redirects the user to the version of the url with a trailing slash so the real content is stored in in the key that has been cached that contains the trailing slash.

http://domain1.com/purge/about is redirected to: http://domain1.com/purge/about/

Both are fastcgi cached, and I can see their keys show up in the cache. I've been trying to use the nginx helper plugin which recommends using this nginx add-in to do the deletes but I haven't been able to get this plugin to work to purge when there is a trailing slash.

location ~ /purge(/.*) { fastcgi_cache_purge DOMAIN1.COM $scheme$request_method$host$1; }

This untranslated key works and deletes the real cache key: httpGETdomain1.com/about

This untranslated key fails to delete the real cache key. It returns a 404 error: httpGETdomain1.com/about/

From the purge url perspective... This deletes the key and works: http://domain1.com/purge/about

This does not delete the key and fails with a 404. I can see the key in the cache and it remains after running this url. http://domain1.com/purge/about/

I verified the value of the purge url untranslated keys, and they are as expected and the one with a trailing slash prints out a trailing slash. location ~ /purge(/.*) { return 200 "untranslated key is $scheme$request_method$host$1";
add_header Content-Type text/plain;

fastcgi_cache_purge DOMAIN1.NET "$scheme$request_method$host$1";

}
pkirk commented 7 years ago

How do you fixed it? https://xkcd.com/979/

kigajewex commented 5 years ago

nginx config

proxy_cache_path /var/nginx_cache levels=1:2 keys_zone=my_cache:20m max_size=200m inactive=2h;
proxy_cache_key $uri;
location ~ /ABEhgTGZzfer3VIdcG8jJX2CJSeRcQGk(/.*) {
    testcookie off;
    allow all;
    proxy_cache_purge my_cache $1;
    error_page 404 /manual_purge.php;
}
location /manual_purge.php {
    internal;
    include snippets/fastcgi-php.conf;
    fastcgi_pass 127.0.0.1:9000;
}

manual_purge.php

<?php
$uri = str_replace('/ABEhgTGZzfer3VIdcG8jJX2CJSeRcQGk', '', $_SERVER['REQUEST_URI']);
$md5 = md5($uri);
$l1 = substr($md5, -1);
$l2 = trim(substr($md5, -3), $l1);
@unlink("/var/nginx_cache/$l1/$l2/$md5");
echo "Successful purge\n";
echo "Key: $uri\n";
echo "Path: /var/nginx_cache/$l1/$l2/$md5";