Nginx series (fifteen nginx clear cache)

WBOY
Release: 2016-08-08 09:23:42
Original
1481 people have browsed it

一.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/
Copy after login

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; } }
Copy after login

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).'/'.substr($url,-3,2).'/'.$url; echo$cacheFile; if (!file_exists($cacheFile)) { echo'缓存不存在!'; } else { if (unlink($cacheFile)) { echo'清除缓存成功'; } else { echo'清除缓存失败'; } } } }
Copy after login

参考:

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Why is "this" defined as undefined in Vue 3 function Please look at the following simple component example in Vue3: