Nginx系列(十五 nginx清除缓存)

原创
2016-08-08 09:23:42 1100浏览

一.nginx 模块清除

1.下载地址:
http://labs.frickle.com/nginx_ngx_cache_purge/
https://github.com/FRiCKLE/ngx_cache_purge

2.安装

./configure --prefix=/web/nginx --with-http_stub_status_module--with-pcre--add-module=/download/ngx_cache_purge-master/

3.配置

server { 
        listen80;
        server_name www.test01.com;

        location / {
            proxy_cache cache_one;
            proxy_cache_valid2003041h;
            proxy_cache_key$host$uri$is_args$args;
            proxy_passhttp://webserver;
            proxy_redirectoff;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location~ /purge(/.*) {
            allow127.0.0.1;
            allow192.168.27.1;
            deny all;
            proxy_cache_purge cache_one $host$1$is_args$args;
        }
    }

4.测试

原url为:http://www.test01.com/Public/Assets/style/default_page.css
清除缓存url:http://www.test01.com/purge/Public/Assets/style/default_page.css

出现如下界面则清除成功:

二.php 清除

$cachePath = '/web/cache/nginx/';
$listcon = file_get_contents('./urls.txt');
$listarr = explode("\n", $listcon);

foreach ($listarras$listval) {
    if (!empty($listval)) {
        $url = md5($listval);
        $cacheFile = $cachePath.substr($url,-1,1).'//m.sbmmt.com/m/'.substr($url,-3,2).'//m.sbmmt.com/m/'.$url;
        echo$cacheFile;

        if (!file_exists($cacheFile)) {
            echo'缓存不存在!';
        } else {
            if (unlink($cacheFile)) {
                echo'清除缓存成功';
            } else {
                echo'清除缓存失败';
            }
        }
    }
}

参考:

http://www.bhqb.org/blog/post-450.html
http://xwsoul.com/posts/460

以上就介绍了Nginx系列(十五 nginx清除缓存),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。