Bulk purge Nginx cache with shell script

Source: Internet
Author: User

Improve web site speed experience in addition to its own web site program optimization, for LINUXSA, there are a lot of work to do, optimize the system kernel, adjust the parameters of the Web server, optimize the database, increase the Web site architecture cache, and so a series of work.

For Web caching, the current mainstream HTTP accelerator is mainly varnish, nginx_proxy, squid, etc., with the Nginx Web high-speed reverse proxy by the use of large and medium-sized Web sites, its integrated caching function (NGINX_PROXY) is increasingly powerful, At present, enterprises are also used in large quantities. Today we'll look at how the Nginx_proxy cache works to clean up. Use the shell script to automate the cleanup, as follows:

#! /bin/sh

#Auto clean Nginx Cache Shell Scripts

#2013 -06-12 WUGK

#Define Path

cache_dir=/data/www/proxy_cache_dir/

File= "$*"

#To determine whether the input script,if not, then exit to determine if the script has input, does not enter and then exits

If

["$#"-eq "0"];then

echo "Please insertclean Nginx cache File, Example: $ index.html index.js"

Sleep 2 && exit

Fi

echo "The file: $FILEto be clean nginx Cache, please waiting ..."

#Wrap processing for the "input" file, for grep lookup, a newline of the entered files, which facilitates grep lookup matching related content

For i in ' echo $FILE |sed ' s//n/g '

Todo

Grep-ra $i ${cache_dir}| Awk-f ': ' {print $} ' >/tmp/cache_list.txt

For J. ' Cat/tmp/cache_list.txt ' do

RM-RF $j

echo "$i $j is deletedsuccess!"

Done

Done

#The Scripts exec Success and exit 0

Following is a screenshot of the execution of the purge script:

Related Article

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.