Skip to content

Simple cache flush tool for nginx

Notifications You must be signed in to change notification settings

remodoy/ngflush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NGFlush

Simple cache flush tool for nginx.

Installation

  • Install python 3.
  • Copy ngflush.ini.sample to /etc/ngflush.ini
  • Edit /etc/ngflush.ini, fix cache_path and cache_levels if needed.
  • Enable systemd service
cp systemd/ngflush.service /etc/systemd/system/ngflush.service
systemctl daemon-reload
systemctl enable ngflush.service
systemctl start ngflush.service
  • Configure Nginx, replace CACHE_KEY with proxy_cache_key value, NORMAL_BACKEND with your backend name and CACHE_NAME with cache name.
upstream proxy-flush {
    server localhost:8000    weight=100;

}

map $request_uri $proxy_target {
    "~*[?&]ngflush=true" proxy-flush;
    default NORMAL_BACKEND;
}

#
map $request_uri $use_cache {
    "~*[?&]ngflush=true" off;
    default CACHE_NAME;
}

...

server {
...


location /ngflush/ {
    proxy_pass http://proxy-flush/multiple/;
}

location / {
  if ($proxy_target = proxy-flush) {
      rewrite ^(.*)$ /single/CACHE_KEY break;
      set $args ""; # Get rid of duplicate arguments
  }

  ...

  proxy_pass http://$proxy_target;
  proxy_cache $use_cache;  # Prevent caching responses from ngflush.

  ...
}

...

}
  • Restart nginx
nginx -t && nginx -s reload

Usage

  • Add &ngflush=true to end of url to flush single page.
  • Use /ngflush/?pattern=regexp[&content-type=regex] to remove multiple pages

License

The MIT License (MIT) Copyright (c) 2016-2024, Remod Oy

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Simple cache flush tool for nginx

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages