由于nginx直接由ubuntu的apt install nginx安装不支持ngx_cache_purge,因此需要不重新编译nginx的情况下,单独生成ngx_cache_purge模块。
1,查看当前nginx版本
/sbin/nginx -V
然后下载对应版本的nginx源码,和ngx_cache_purge源码
2,修改ngx_cache_purge的连接方式
打开ngx_cache_purge目录下的config文件,修改如下
if [ "$HTTP_PROXY" = "YES" ]; then
have=NGX_HTTP_PROXY . auto/have
fi
if [ "$HTTP_FASTCGI" = "YES" ]; then
have=NGX_HTTP_FASTCGI . auto/have
fi
if [ "$HTTP_SCGI" = "YES" ]; then
have=NGX_HTTP_SCGI . auto/have
fi
if [ "$HTTP_UWSGI" = "YES" ]; then
have=NGX_HTTP_UWSGI . auto/have
fi
ngx_addon_name=ngx_http_cache_purge_module
CACHE_PURGE_SRCS="$ngx_addon_dir/ngx_cache_purge_module.c"
if [ -n "$ngx_module_link" ]; then
ngx_module_type=HTTP
ngx_module_name="$ngx_addon_name"
ngx_module_srcs="$CACHE_PURGE_SRCS"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_cache_purge_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_cache_purge_module.c"
fi
have=NGX_CACHE_PURGE_MODULE . auto/have
3,进入nginx源码目录
./configure --add-dynamic-module=/ngx_cache_purge目录 --with-compat
make modules
4,在nginx源码的objs目录下会生成ngx_http_cache_purge_module.so
5,拷贝ngx_http_cache_purge_module.so到/usr/lib/nginx/modules/
6,编辑nginx.conf
在events前添加
load_module modules/ngx_http_cache_purge_module.so;
#必须在events前添加
events {