当前位置: 首页 » 产品 » 家居百货 » 正文

使用Shell脚本批量清除Nginx缓存

放大字体  缩小字体 发布日期: 2024-09-25 12:20   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:13
核心提示:  提高网站速度体验除了本身网站程序优化外,对于LinuxSA来说还有大量的工作要做,优化系统内核、调整Web服务器的参数、优化数

  提高网站速度体验除了本身网站程序优化外,对于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=http://www.3lian.com/data/www/proxy_cache_dir/

  FILE="$*"

  #To determine whether the input script,If not, then exit 判断脚本是否有输入,没有输入然后退出

  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,对输入的文件进行换行处理,利于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 DeletedSuccess !"

  done

  done

  #The scripts exec success and exit 0

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

使用Shell脚本批量清除Nginx缓存 三联

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站