提高網(wǎng)站速度體驗(yàn)除了本身網(wǎng)站程序優(yōu)化外,對(duì)于LinuxSA來(lái)說(shuō)還有大量的工作要做,優(yōu)化系統(tǒng)內(nèi)核、調(diào)整Web服務(wù)器的參數(shù)、優(yōu)化數(shù)據(jù)庫(kù)、增加網(wǎng)站架構(gòu)緩存等等一系列的工作。
對(duì)于網(wǎng)站緩存,目前主流的HTTP加速器主要有Varnish、Nginx_proxy、Squid等,隨著Nginx Web 高速反向代理被各大中型網(wǎng)站使用,其集成緩存的功能(Nginx_proxy)也日益強(qiáng)大,目前企業(yè)中也在大量使用。今天我們來(lái)研究一下 Nginx_Proxy緩存如何有效的來(lái)清理。如下使用Shell腳本來(lái)自動(dòng)化清理,直接上腳本如下:
#! /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 判斷腳本是否有輸入,沒(méi)有輸入然后退出
if
[ "$#" -eq "0" ];then
echo "Please Insertclean Nginx cache File, Example: $0 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,對(duì)輸入的文件進(jìn)行換行處理,利于grep查找匹配相關(guān)內(nèi)容
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 DeletedSuccess !"
done
done
#The Scripts exec success and exit 0
如下為執(zhí)行清除腳本后的截圖:
新聞熱點(diǎn)
疑難解答
圖片精選