IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    ngx_cache_puage更新缓存404错误

    C1G发表于 2022-02-21 09:43:08
    love 0

    在清除缓存时部分成功部分失败,有时通过浏览器可以但用程序就失败.

    location ~ /purge(/.*)
    {
    	#设置只允许指定的IP或IP段才可以清除URL缓存。
    	allow            127.0.0.1;
    	allow            192.168.0.0/16;
    	include manageip.conf;
    	deny            all;
    	proxy_cache_purge    cache_www   $host$1$is_args$args;
    	error_page 405 =200 /purge$1; #处理squidclient purge的时候出现的405错误
    }    
    if ( $request_method = "PURGE" ) {
    	rewrite ^(.*)$ /purge$1 last;
    }
    
    模拟测试
    curl -H "Host:blog.c1gstudio.com" -H "User-Agent: c1gtest"  -X PURGE http://blog.c1gstudio.com/static/image/common/qrcode.png
    <html>
    <head><title>404 Not Found</title></head>
    <body>
    <center><h1>404 Not Found</h1></center>
    <hr><center>openresty</center>
    </body>
    </html>
    

    去掉权限,并输出url,发现没有$1的输出
    location ~ /purge(/.*)
    {
    #设置只允许指定的IP或IP段才可以清除URL缓存。
    allow 127.0.0.1;
    allow 192.168.0.0/16;
    echo cache_bbs $host$1$is_args$args;
    error_page 405 =200 /purge$1; #处理squidclient purge的时候出现的405错误
    }

    curl -H “Host:blog.c1gstudio.com” -H “User-Agent: c1gtest” -X PURGE http://blog.c1gstudio.com/static/image/common/qrcode.png
    cache_bbs: blog.c1gstudio.com

    可能是$1被其它脚本占用,重新定义一个 $purgeurl变量
    location ~ /purge(?<purgeurl>/.*)
    {
    	#设置只允许指定的IP或IP段才可以清除URL缓存。
    	allow        127.0.0.1;
    	allow        192.168.0.0/16;
    	echo    cache_bbs   $host$purgeurl$is_args$args;
    	error_page 405 =200 /purge$1; #处理squidclient purge的时候出现的405错误
    }    
    
    测试可以输出
    curl -H "Host:blog.c1gstudio.com" -H "User-Agent: c1gtest"  -X PURGE http://blog.c1gstudio.com/static/image/common/qrcode.png
    cache_bbs: blog.c1gstudio.com/static/image/common/qrcode.png
    
    最后修改并测试成功
    location ~ /purge(?<purgeurl>/.*)
    {
    	#设置只允许指定的IP或IP段才可以清除URL缓存。
    	allow        127.0.0.1;
    	allow        192.168.0.0/16;
    	include manageip.conf;
    	deny            all;
    	proxy_cache_purge    cache_bbs   $host$purgeurl$is_args$args;
    	error_page 405 =200 /purge$purgeurl; #处理squidclient purge的时候出现的405错误
    }    
    if ( $request_method = "PURGE" ) {
    	rewrite ^(.*)$ /purge$1 last;
    }      
    
    curl -H "Host:blog.c1gstudio.com" -H "User-Agent: c1gtest"  -X PURGE http://blog.c1gstudio.com/static/image/common/qrcode.png
    <html>
    <head><title>Successful purge</title></head>
    <body bgcolor="white">
    <center><h1>Successful purge</h1>
    <br>Key : blog.c1gstudio.com/static/image/common/qrcode.png
    <br>Path: /dev/shm/nginx/proxy_cache_bbs/1/92/9a7ee4d7167bc0ead33f4ccdb4439921
    </center>
    <hr><center>openresty/1.19.9.1</center>
    </body>
    </html>
    
    

    Related Posts

    • Farseer – Nginx for Windows 快速配置包 ( 2009-06-03)
    • linux下查看nginx,apache,mysql,php的编译参数[转] ( 2009-05-21)
    • nginx rewrite 参数和例子 ( 2009-04-16)

    The post ngx_cache_puage更新缓存404错误 first appeared on C1G军火库.



沪ICP备19023445号-2号
友情链接