Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to batch clear cache by proxy_cache in nginx

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how proxy_cache bulk clears caches in nginx. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Previously, using the official nginx proxy_cache as the CDN static cache, it was found that it was a big problem for this module to clean up the cache, which could only be cleared one by one url. For this reason, a script was written to batch clear the cache.

The main features include:

1. Clean up by file typ

two。 Clean up by specific file name

3. Clean up by site directory

Here is the bash shell script code. There have been a lot of similar scripts on the Internet before, but they don't feel good and are easy to mislead people to make mistakes.

#! / bin/bash#Email:hello_linux@aliyun.com#Auto Clean Nginx Proxy_Cache Shell Scripts#Aunthor:sun~shell#Date:2017-02-23echo-e "\ n\ n"\ e [35th 1m Please enter the specific path of the Nginx Proxy_cache cache (friendly reminder: you can use the Tab completion function!)\ e [0m\ e [34th 5m:\ e [0m "read-e pathCACHE_DIR=$pathecho-e"\ e [32] 1m echo echo -\ e [0m "house-e"\ e [32] 1m / m / m Delete\ T2 by file type. Delete\ T3 by specific file name. Delete from the file directory\ n: "read action case $action in1) echo-e"\ e [32th 1m echo-e [0m "Murray-e"\ e [32 1m Mustang -\ e [0m "echo-n-e"\ e [34th 1m Please enter the type of cache file you want to delete (separated by multiple parameter spaces)\ e [0m\ e [34] 5m:\ e [0m "read-a FILEfor i in `echo ${FILE [*]} | sed's / /\ nAccording g'r-a\ .$ I {CACHE_DIR} | awk 'BEGIN {FS=": "} {print $1}' > / tmp/cache_list.txt for j in `cat / tmp/cache_ list.txt`do rm-rf $j echo" $I $j deleted successfully! " Donedone;;2) echo-e "\ e [321m Murray Murray-[0m" echo-e "\ e [32] 1m "echo-n-e"\ e [0m "Mustang-n-e"\ e [33bet1m] Please enter the specific name of the cache file you want to delete (separated by multiple parameter spaces)\ e [0m\ e [34] 5m:\ e [0m "read-a FILEfor i in `echo ${FILE [*]} | sed's / /\ nAccording g'r-a $I ${CACHE_DIR} | awk 'BEGIN {FS=": "} {print $1}' > / tmp/cache_list.txt for j in `cat / tmp/cache_ list.txt`do rm-rf $j echo" $I $j deleted successfully! " Donedone;;3) echo-e "\ e [321m Murray Murray-[0m" echo-e "\ e [32] The models supported by 1m "echo-n-e" [0m "Murray-n-e"\ e [33 + + 1m] are:\ N1. Clear all caches in the store directory of the website: test.dd.com/data/upload/shop/store\ n2. Clear all caches under the website shop: test.dd.com/data/upload/shop\ e [0m\ n "echo-n-e"\ e [34bot 1m Please enter the specific directory of the cache files you want to delete\ e [0m\ e [34] 5m:\ e [0m "read-a FILEfor i in `echo ${FILE [*]} | sed's / /\ nAccording g'l dogrep-r-a" $I "${CACHE_DIR} | awk 'BEGIN {FS=": "} {print $1}' > / tmp/cache_list.txt for j in `cat / tmp/cache_ list.txt`do rm-rf $j echo" $I $j deleted successfully! " Donedone;;*) echo "input error, please re-enter";; esac Thank you for reading! This is the end of the article on "how to batch clear the cache in nginx". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report