nginx-cache-purge

 

 

 


nginx-cache-purge

 

Source

https://github.com/FRiCKLE/ngx_cache_purge

Usage

# Allow purging of selected pages from FastCGI's cache.
fastcgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]

# Allow purging of selected pages from proxy's cache.
proxy_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]

# Allow purging of selected pages from uWSGI's cache.
uwsgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]

*_cache_purge 的 context: location

P.S.

debian package nginx-naxsi 自身包含它, nginx-full 反而沒有.

Example configuration:

e.g.

http {
      ..........
      server {
          location / {
              proxy_pass         http://127.0.0.1:8000;
              proxy_cache        tmpcache;

              # Default:         $scheme$proxy_host$request_uri
              proxy_cache_key	 $uri$is_args$args;

              proxy_cache_purge  PURGE from 127.0.0.1;
          }
}

e.g.

    http {
        proxy_cache_path  /tmp/cache  keys_zone=tmpcache:10m;

        server {
            location / {
                proxy_pass         http://127.0.0.1:8000;
                proxy_cache        tmpcache;

                # Default:         $scheme$proxy_host$request_uri
                proxy_cache_key    $host$uri$is_args$args;
            }

            location ~ /purge(/.*) {
                allow              127.0.0.1;
                deny               all;

                # proxy_cache_purge zone_name key
                proxy_cache_purge  tmpcache $host$1$is_args$args;
            }
        }
    }

Usage:

假設以下資源被 Cache 了

http://datahunter.org/themes/mytheme/logo.png

Purge it with curl:

curl http://datahunter.org/purge/themes/mytheme/logo.png

<html>
<head><title>Successful purge</title></head>
<body bgcolor="white">
<center><h1>Successful purge</h1>
<br>Key : datahunter.org/themes/mytheme/logo.png
<br>Path: /var/cache/nginx/cache/2/3ef6b8699162cab017ba8ad8889ab0e2
</center>
<hr><center>nginx/1.1.19</center>
</body>
</html>

 


 

 

Creative Commons license icon Creative Commons license icon