重新编译nginx增加模块(反代相关)
1、find / -name nginx-1
/usr/local/nginx-1.18/sbin/nginx
/usr/local/nginx-generic-1.18/sbin/nginx
2、根据查出的目录查看编译参数并保存,注意去掉 “arguments:”
如:/usr/local/nginx-1.18/sbin/nginx -V
3、下载nginx相应版本
wget http://nginx.org/download/nginx-1.18.0.tar.gz
4、解压
tar xf nginx-1.18.0.tar.gz
5、Nginx 的内容替换功能,集成第三方的替换模块:ngx_http_substitutions_filter_module报错误,
确认配置参数包含以下两项:--with-http_sub_module --add-module=/git/ngx_http_substitutions_filter_module
没有需要用git签出subs_filter的源码(参考 nginx_substitutions_filter)。
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
(注:保存路径为/git/ngx_http_substitutions_filter_module)
6、进入nginx目录
cd nginx-1.18.0
7、重新编译的代码和模块
./configure --prefix=/usr/local/nginx-1.18 --user=www --group=www --with-http_ssl_module --with-openssl=/home/usrdata/nginx-1.18/openssl-1.0.2u --with-http_gzip_static_module --with-http_v2_module --with-threads --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_ssl_module --with-http_sub_module --add-module=/git/ngx_http_substitutions_filter_module
./configure --prefix=/usr/local/nginx-1.18 --user=www --group=www --with-http_ssl_module --with-openssl=/home/usrdata/nginx-1.18/openssl-1.0.2u --with-http_gzip_static_module --with-http_v2_module --with-threads --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_sub_module --add-module=/git/ngx_http_substitutions_filter_module
8、执行 make (注意:千万别 make install ,否则就覆盖安装了)
make完之后在nginx-1.18.0/objs目录下就多了个nginx,这个就是新版本的程序了。
9、cd到objs目录测试一下新编译的nginx
./nginx -t
如果看到
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
那就表示测试通过可以使用了
10、备份旧的nginx程序
cd /usr/local/nginx-1.18/sbin/
mv nginx nginx_bak
11、把新的nginx程序复制到/usr/local/nginx-1.18/sbin/下
cp /root/nginx-1.18.0/objs/nginx /usr/local/nginx-1.18/sbin/
12、测试新的nginx程序是否正确
/usr/local/nginx-1.18/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
13、平滑启动服务
/usr/local/nginx-1.18/sbin/nginx -s reload
14、查看模块是否已安装
/usr/local/nginx-1.18/sbin/nginx -V
nginx version: nginx/1.10.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
15、重启Nginx
./nginx -s quit
./nginx
nginx重新加载模块完成!