首先介绍一下弄这个的初衷。
其实初衷很简单公司需要这个,然后你就去实现没有什么更高大上的理由,原理什么的我也不打算介绍了,个人不太喜欢这些咬文爵字的东西。
其次做这个需要用到ngx_cache_purge 缓存模块。
不清楚自己的nginx有没有添加这个模块的童鞋可以使用nginx -V查看具体如下:
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.10.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --add-module=/root/ngx_cache_purge-2.3 --with-http_perl_module --with-ld-opt=-Wl,-E
如果看到了ngx_cache_purge则已经添加了这个模块。你可以直接跳到最下面看看是不是你想要的,好了,废话不多说。
一、编译安装Nginx
首先下载nginx和ngx_cache_purge 缓存模块
附: nginx下载地址:http://nginx.org/download/nginx-1.10.3.tar.gz ngx_cache_purge下载地址:http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
开始编译安装
cd /usr/local/
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar zxvf nginx-1.10.3.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
tar -xvf ngx_cache_purge-2.3.tar.gz
./configure --prefix=/usr/local/nginx --add-module=../ngx_cache_purge-2.3 --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_perl_module --with-ld-opt="-Wl,-E"
附Nginx编译安装时可能遇到的问题:
/configure: error: the HTTP rewrite module requires the PCRE library.
解决方法:安装pcre
# yum -y install pcre pcre-devel
缺少ssl错误,错误信息如下:
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=
|