nginx反向代理及缓存清理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx反向代理及缓存清理相关的知识,希望对你有一定的参考价值。
#下载安装包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.41.tar.bz2
#--------------- 在未安装nginx的情况下安装ngx_cache_purge ---------------#
cd nginx-1.13.7
./configure --prefix=/usr/local/nginx \
--with-pcre=/opt/pcre-8.41 \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module
--add-module=/opt/ngx_cache_purge-2.3
make
make install
#--------------- 在已安装nginx情况下安装ngx_cache_purge ---------------#
cd nginx-1.13.7
./configure --prefix=/usr/local/nginx \
--with-pcre=/opt/pcre-8.41 \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module
--add-module=/opt/ngx_cache_purge-2.3
make //千万不要make install,不然就真的覆盖了
/etc/init.d/nginx stop
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp objs/nginx /usr/local/nginx/sbin/nginx
#nginx反向代理及缓存清理
#user nobody;
worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
}
#---------------- nginx缓存清理脚本 ------------------------#
cat atuo_nginx_cache_clean.sh
#!/bin/bash
mfile="$*"
cache_dir=/data/cache1
echo $mfile
if [ "$#" -eq 0 ]
then
echo "please input scripts, if not, it will exit"
sleep 2 && exit
fi
echo "what you put $mfile will delete, please wait..."
for i in echo $mfile | sed ‘s/ /\n/g‘
do
grep -ira $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 delete Success!"
done
done
#脚本用法
./atuo_nginx_cache_clean.sh aa.jpg bb.js cc.html
以上是关于nginx反向代理及缓存清理的主要内容,如果未能解决你的问题,请参考以下文章