当前位置: 移动技术网 > 网络运营>服务器>Linux > Shell脚本批量清除Nginx缓存

Shell脚本批量清除Nginx缓存

2017年12月12日  | 移动技术网网络运营  | 我要评论

前言*随着整个互联网的发展,产生了无数大大小小的网站,随之而来用户对网站ui和速度体验也在日益加强,对企业或者个人来说,赢得用户体验也就意味着赢得先机。

那今天我们在这里针对网站速度这方面来一起交流,提高网站速度对于运维工程师、程序员来说变得至关重要。运维工程师首先得在日常网站运维中发现影响网站速度的各种因素得逐个推动然后解决。

提高网站速度体验除了本身网站程序优化外,对于linuxsa来说还有大量的工作要做,优化系统内核、调整web服务器的参数、优化数据库、增加网站架构缓存等等一系列的工作。

对于网站缓存,目前主流的http加速器主要有varnish、nginx_proxy、squid等,随着nginx web 高速反向代理被各大中型网站使用,其集成缓存的功能(nginx_proxy)也日益强大,目前企业中也在大量使用。今天我们来研究一下nginx_proxy缓存如何有效的来清理。如下使用shell脚本来自动化清理,直接上脚本如下:

复制代码 代码如下:

#! /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 判断脚本是否有输入,没有输入然后退出
if
 [  "$#" -eq "0" ];then
 echo "please insert clean nginx cache file, example: $0 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

如下为执行清除脚本后的截图:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网