Heim > Backend-Entwicklung > PHP-Tutorial > Nginx-Serie (fünfzehn Nginx-Cache löschen)

Nginx-Serie (fünfzehn Nginx-Cache löschen)

WBOY
Freigeben: 2016-08-08 09:23:42
Original
1566 Leute haben es durchsucht

一.nginx 模块清除

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

2.安装

<code><span>.</span>/configure <span>--</span>prefix<span>=</span>/web/nginx <span>--</span><span>with</span><span>-http_stub_status_module</span><span>--</span><span>with</span><span>-pcre</span><span>--</span>add<span>-module</span><span>=</span>/download/ngx_cache_purge<span>-master</span><span>/</span></code>
Nach dem Login kopieren

3.配置

<code><span>server</span> { 
        <span>listen</span><span>80</span>;
        <span>server_name</span> www.test01.com;

        <span>location</span> / {
            <span>proxy_cache</span> cache_one;
            <span>proxy_cache_valid</span><span>200</span><span>304</span><span>1h</span>;
            <span>proxy_cache_key</span><span>$host</span><span>$uri</span><span>$is_args</span><span>$args</span>;
            <span>proxy_pass</span><span>http://webserver</span>;
            <span>proxy_redirect</span><span>off</span>;
            <span>proxy_set_header</span> Host <span>$host</span>;
            <span>proxy_set_header</span> X-Real-IP <span>$remote_addr</span>;
            <span>proxy_set_header</span> X-Forwarded-For <span>$proxy_add_x_forwarded_for</span>;
        }

        <span>location</span><span>~ /purge(/.*)</span> {
            <span>allow</span><span>127.0.0.1</span>;
            <span>allow</span><span>192.168.27.1</span>;
            <span>deny</span> all;
            <span>proxy_cache_purge</span> cache_one <span>$host</span><span>$1</span><span>$is_args</span><span>$args</span>;
        }
    }</code>
Nach dem Login kopieren

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 清除

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

<span>foreach</span> (<span>$listarr</span><span>as</span><span>$listval</span>) {
    <span>if</span> (!<span>empty</span>(<span>$listval</span>)) {
        <span>$url</span> = md5(<span>$listval</span>);
        <span>$cacheFile</span> = <span>$cachePath</span>.substr(<span>$url</span>,-<span>1</span>,<span>1</span>).<span>'/'</span>.substr(<span>$url</span>,-<span>3</span>,<span>2</span>).<span>'/'</span>.<span>$url</span>;
        <span>echo</span><span>$cacheFile</span>;

        <span>if</span> (!file_exists(<span>$cacheFile</span>)) {
            <span>echo</span><span>'缓存不存在!'</span>;
        } <span>else</span> {
            <span>if</span> (unlink(<span>$cacheFile</span>)) {
                <span>echo</span><span>'清除缓存成功'</span>;
            } <span>else</span> {
                <span>echo</span><span>'清除缓存失败'</span>;
            }
        }
    }
}</code>
Nach dem Login kopieren

参考:

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

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

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage