Toggle navigation
首页
技术
骑行
羽毛球
资讯
联络我
登录
Nginx(Docker)代理层缓存清理ngx_cache_purge
2017-11-02
Nginx
Performance
> Nginx商业版提供了Purger功能,对于社区版,可以使用第三方模块ngx_cache_purge来清理缓存 本文介绍如何基于官方的 Nginx docker image 来制作包含ngx_cache_purge的image,如果不使用docker image,将Dockerfile中的script稍作修改即可。 # Dockerfile 这里直接fork了一份已经做好的,将版本升级到当前最新:nginx 1.13.6, ngx_cache_purge 2.4.2 https://github.com/xiaoxin01/nginx-purge-docker/blob/master/Dockerfile 改动的内容 ``` FROM nginx:1.13.6 ENV NGX_CACHE_PURGE_VERSION=2.4.2 # Install basic packages and build tools RUN apt-get update && \ apt-get install --no-install-recommends --no-install-suggests -y \ wget \ ca-certificates \ zlib1g-dev \ ``` # 配置代理层缓存 参考:[Nginx代理层缓存](/Coding/Details/proxy-cache-in-nginx) # 配置 purge 有两种配置方式: ## Sample configuration (same location syntax) ``` http { proxy_cache_path /tmp/cache keys_zone=cache:10m; server { location / { proxy_pass http://127.0.0.1:8000; proxy_cache cache; proxy_cache_key $uri$is_args$args; proxy_cache_purge PURGE from 127.0.0.1; } } } ``` 对于这种方式,清除缓存的方法是使用 PURGE 命令。 比如要清除:http://localhost/lib/bootstrap/dist/css/bootstrap.css 命令如下: curl http://localhost/lib/bootstrap/dist/css/bootstrap.css -X PURGE ## Sample configuration (separate location syntax) ``` http { proxy_cache_path /tmp/cache keys_zone=cache:10m; server { location / { proxy_pass http://127.0.0.1:8000; proxy_cache cache; proxy_cache_key $uri$is_args$args; } location ~ /purge(/.*) { allow 127.0.0.1; deny all; proxy_cache_purge cache $1$is_args$args; } } } ``` 对于这种方式,清除方法是将资源路径加上 purge。 比如要清除:http://localhost/lib/bootstrap/dist/css/bootstrap.css 命令如下: curl http://localhost/purge/lib/bootstrap/dist/css/bootstrap.css # 参考: * [ngx_cache_purge](https://github.com/FRiCKLE/ngx_cache_purge/)
×
本文为博主原创,如需转载,请注明出处:
http://www.supperxin.com
返回博客列表