网站制作学习网经验与学习→正文:Nginx 清理缓存添加安装模块 ngx_cache_purge
字体:

Nginx 清理缓存添加安装模块 ngx_cache_purge

经验与学习 2023/6/30 16:19:54  点击:不统计

%77w%77%2Ef%6F%72p%73%70%2Ec%6E

1. 如果你没有安装nginx ,按可以在安装时添加 purge模块
2. 安装清除CDN  cache 模块。下载模块地址:http://labs.frickle.com/files/
3. 如果你已经安装了nginx ,需要安装上面扩展,
(1)先看一下历史的安装信息
nginx -V
结果:--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.8/src/openssl-1.1.1k --with-openssl-opt='enable-weak-ssl-ciphers' --with-ld-opt='-ljemalloc' 
(2)解压扩展到 /root/ngx_cache_purge-2.3, 然后找到自己nginx 对应版本安装目录, 将上面的 配置加上最后一个 扩展陪孩子
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.8/src/openssl-1.1.1k --with-openssl-opt='enable-weak-ssl-ciphers' --with-ld-opt='-ljemalloc' --add-module=/root/ngx_cache_purge-2.3
(3)上面运行没有错误,则开始make   切记,运行如果没有问题,这里配置就结束了。注意:不要 不要运行make install
(4) 备份原始 nginx bin文件,一般在/usr/bin/nginx ,要看一下这个文件有可能是软连接,要看实际路径 停止运行的nginx  mv /usr/bin/nginx /usr/bin/nginx.bak
(5)到ngixn 安装文件夹下的 objs 找到nginx 复制到 /usr/bin/nginx 位置
(6) 启动nginx 看nginx -V 看是否已经安装成功
 
4. 在 server中添加purge请求处理规则配置。注意,注意: purge  处理一定要在 proxy_cache 之后,否则会出现404 问题
参考下面代码, 一定要注意key 的一致性  
location / {
proxy_cache cache_one;
proxy_cache_key $isapple$ismobile$server_port$request_uri;
proxy_cache_valid  200 304 6h;
add_header X-Cache $upstream_cache_status;
proxy_ignore_headers Set-Cookie;
proxy_set_header   Host  $host;
proxy_pass https://rrdms;
}
location ~ /purge(/.*) { 
allow        all;
proxy_cache_purge cache_one $isapple$ismobile$server_port$1;# 这里的$1 是对应purge 后面的uri 已经是cache 的uri
}
 
5.然后 请求 domain.com/purge/xx.html 就可以清除缓存了

http://www.forasp.cn/

·上一篇:nginx配置判断是PC还是移动端 >>    ·下一篇:nginx referer防盗连 >>
推荐文章
最新文章