前言*随着整个互联网的发展,产生了无数大大小小的网站,随之而来用户对网站ui和速度体验也在日益增强,对企业或者我的来讲,赢得用户体验也就意味着赢得先机。html
那今天咱们在这里针对网站速度这方面来一块儿交流,提升网站速度对于运维工程师、程序员来讲变得相当重要。运维工程师首先得在平常网站运维中发现影响网站速度的各类因素得逐个推进而后解决。linux
提升网站速度体验除了自己网站程序优化外,对于linuxsa来讲还有大量的工做要作,优化系统内核、调整web服务器的参数、优化数据库、增长网站架构缓存等等一系列的工做。nginx
对于网站缓存,目前主流的http加速器主要有varnish、nginx_proxy、squid等,随着nginx web 高速反向代理被各大中型网站使用,其集成缓存的功能(nginx_proxy)也日益强大,目前企业中也在大量使用。今天咱们来研究一下nginx_proxy缓存如何有效的来清理。以下使用shell脚原本自动化清理,直接上脚本以下:程序员
复制代码 代码以下:web
#! /bin/sh
#auto clean nginx cache shell scripts
#2013-06-12 wugk
#define path
cache_dir=/data/www/proxy_cache_dir/
file="$*"shell
#to determine whether the input script,if not, 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,对输入的文件进行换行处理,利于grep查找匹配相关内容
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
缓存
以下为执行清除脚本后的截图:服务器
总结:架构
脚本写的很差,大神勿喷,可能还有优化的,欢迎你们批评指导