简介
今天搭建网站的时候发现原来编译好的nginx中没有我需要的模块,这个时候就需要往nginx中动态的添加模块了
操作
首先看一下自己现在的nginx版本
1 | [root@vultr src]# nginx -V |
上面有编译的参数,这个很重要
之后下载对应的nginx版本,解压tar -zxvf nginx-1.10.0.tar.gz
下载模块git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
cd nginx-1.10.0
接着编译,编译的时候要加入要增加模块只要在编译的时候添加–add-module后面加上模块路径就好了./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=../ngx_http_google_filter_module --add-module=../ngx_http_substitutions_filter_module
接着make记住不能make install
之后替换nginx二进制文件cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp objs/nginx /usr/local/nginx/sbin/
测试新的nginx是否正确
1 | [root@vultr sbin]# ./nginx -t |
重启服务器sudo service nginx reload
完成
Have Fun