The removal of Nginx built-in cache Proxy_cache

Source: Internet
Author: User
nginx third-party module

Can directly add the module on the original basis, only one access, more trouble

#wget http://labs.frickle.com/files/ngx_cache_purge-2.0.tar.gz
#tar-xzf ngx_cache_purge-2.0.tar.gz
On the basis of the original compilation (–add-module=. /ngx_cache_purge-2.0), note the decompression path
#cd nginx-1.6.2
#./configure–user=nginx–group=nginx–prefix=/usr–sbin-path=/usr/sbin/nginx–conf-path=/etc/nginx/nginx.conf– error-log-path=/var/log/nginx/error.log–http-log-path=/var/log/nginx/access.log–pid-path=/var/run/nginx/ Nginx.pid–lock-path=/var/lock/nginx.lock–with-http_ssl_module–with-http_flv_module–with-http_stub_status_ module–with-http_gzip_static_module–http-client-body-temp-path=/var/tmp/nginx/client/–http-proxy-temp-path=/ var/tmp/nginx/proxy/–http-fastcgi-temp-path=/var/tmp/nginx/fcgi/–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi– Http-scgi-temp-path=/var/tmp/nginx/scgi–with-pcre–with-http_image_filter_module–with-file-aio–add-module=. /ngx_cache_purge-2.0>/dev/null

The

Modify Nginx configuration is as follows:

  server {Listen 80;

        server_name www.mytest.com;

        #charset Koi8-r;
#access_log Logs/host.access.log Main;
         #清除缓存, be sure to put it in front (to clear http://www.mytest.com/hello/index.html, Access http://www.mytest.com/purge/hello/index.html)
            Location ~/purge (/.*) {allow 127.0.0.1;
            Allow 192.168.1.0/24;
            Deny all;
        Proxy_cache_purge One_cache $host $1$is_args$args; } location ~. *\.
            (html|htm|css|js|ico|jpeg|git|jpg|png|bmp|swf) $ {Root/home/test/apache-tomcat-7.0.64/webapps/hello;
            Proxy_pass http://mytest;
            Proxy_set_header Host $host;
            Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

            Proxy_set_header X-real-ip $remote _addr;
            Proxy_cache One_cache;
            Proxy_cache_valid 304 301 302 1d;
            Proxy_cache_valid any 6h;
            Proxy_cache_key $host $uri$is_args$args; Add_header X-cache '$upstream _cache_status from $host ';
            } location ~. *$ {proxy_set_header Host $host;
            Proxy_set_header X-real-ip $remote _addr;
            Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
            Proxy_pass http://mytest;
        Add_header X-cache ' $upstream _cache_status from $host '; }
shell Script Cleanup

Can be cleared in batches, here is just the simplest script, there are many imperfections

#!/bin/bash
mfile= "$*"
Cache_dir=/etc/nginx/proxy_cache
echo $mfile
if ["$#"-eq 0]
    Then echo "Please input scripts, if not, it'll exit"
    sleep 2 && exit
fi
echo "What do you put $mfile would de Lete, please wait ... "for
i in ' echo $mfile | sed ' s//\n/g ' do
    grep-ira $i $cache _dir | awk-f ': ' {pri  NT $ ' >/tmp/cache_list.txt for
    J in ' Cat/tmp/cache_list.txt ' does
        rm-rf $j
        echo "$i $j is delete Success! "
    Done
Rm-rf/tmp/cache_list.txt

Operations such as:

If 1.jpg and 11.jpg will be deleted at the same time, so be precise to delete a picture or use a third-party library Ngx_cache_purge. If you want to delete all the pictures in. jpg format, you can directly./1.sh jpg

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.