nginx 反向代理 , 无后缀名的url缓存删除
最近公司用 nginx 做前端反向代理 , web 站点采用 ASP.NET MVC3 开发的 , 所有的 URL 都没有后缀名 , 但是 nginx purge 清除缓存模块 , 我只会配置带有后缀名的删除方式 , 无奈之下 只好写了一个 linux shell 脚本来删除不带有后缀名的 单 URL 缓存 , 如下
#!/bin/bash
# Program :
# It is clear nginx cache the script
# History :
# 2012/09/07
read -p "Please enter url : " url
read -p "Are you sure (y/n) ? $url " yn
if [ "$yn" == "y" ] || [ "$yn"=="Y" ] ; then
md5txt=`echo "$url" | md5sum | awk '{print $1}'`
dirpath=`echo "$md5txt" | awk '{print "/usr/local/nginx/proxy_cache/"substr($0,length($0),1)"/"substr($0,length($0)-2,2)"/"$0}'`
echo "$dirpath"
read -p "Do you want to delete the file :$dirpath , Are you sure (y/n) ?" ydn
if [ "$ydn" == "y" ] || [ "$ydn" == "Y" ] ; then
rm -rf "$dirpath"
echo "delete success"
fi
fi
exit 0