1. 程式人生 > >nginx反向代理及緩存清理

nginx反向代理及緩存清理

labs info gzip oss sha watermark wget $* ice

#下載安裝包
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反向代理及緩存清理