Batch clear Nginx cache using Shell scripts

Source: Internet
Author: User
Preface * with the development of the entire Internet, there have been countless websites, large and small. As a result, users are increasingly enhancing their website UI and speed experience. For enterprises or individuals, winning the user experience means winning the lead. Today, we are here to talk about the website speed. Improving the website speed is crucial for O & M engineers and programmers. O & M engineers must first find various factors affecting the website speed in Daily website O & M and then solve them one by one. In addition to website program optimization, improving website speed and experience is also significant for LinuxSA

Preface * with the development of the entire Internet, there have been countless websites, large and small. As a result, users are increasingly enhancing their website UI and speed experience. For enterprises or individuals, winning the user experience means winning the lead.

Today, we are here to talk about the website speed. Improving the website speed is crucial for O & M engineers and programmers. O & M engineers must first find various factors affecting the website speed in Daily website O & M and then solve them one by one.

In addition to website program optimization, there is still a lot of work to be done for LinuxSA to improve website speed and experience, optimizing the system kernel, adjusting WEB Server parameters, optimizing the database, and adding the website architecture cache.

For website cache, the mainstream HTTP accelerators include Varnish, Nginx_proxy, and Squid. As Nginx WEB High-Speed Reverse Proxy is used by various large and medium-sized websites, its integrated cache function (Nginx_proxy) it is also increasingly powerful and is also widely used by enterprises. Today, we will study how the Nginx_Proxy cache can be effectively cleared. The script is 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 whether the script has input, no input, and then exit

If

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

Echo "Please Insert clean Nginx cache File, Example: $0 index.html index. js"

Sleep 2 & exit

Fi

Echo "The file: $ FILE to be clean nginx Cache, please waiting ....."


# Wrap processing for the input file, for grep lookup, to Wrap the input file, facilitating grep searching for Matching content

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

Do

Grep-ra $ I $ {CACHE_DIR} | awk-F ': ''{print $1}'>/tmp/cache_list.txt

For j in 'cat/tmp/cache_list.txt'

Do

Rm-rf $ j

Echo "$ I $ j is Deleted Success! "

Done

Done

# The Scripts exec success and exit 0

After the script is cleared:

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.