Nginx动态添加模块
已经安装nginx但想要添加一个新模块,这就需要动态添加模块。现在以添加ngx_http_google_filter_module为例作为演示。
1.备份原文件
# 停止服务
/usr/local/nginx/sbin/nginx -s stop
# 将原nginx执行文件备份
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
2.下载ngx_http_google_filter_module模块
cd /usr/local/nginx/module
git clone https://github.com/openresty/echo-nginx-module.git
3.查看原nginx安装了那些模块
/usr/local/nginx/sbin/nginx -V
可以看出编译安装使用了 configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
4.编译时添加新模块
/usr/local/nginx/nginx-1.14.0/configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=/usr/local/nginx/module/echo-nginx-module
5.编译
make
6.替换nginx二进制文件
# 将新生成的nginx复制到/usr/local/nginx/sbin/下
cp /usr/local/nginx/nginx-1.14.0/objs/nginx /usr/local/nginx/sbin/
平滑升级
1.下载想要升级的nginx包
wget http://nginx.org/download/nginx-1.21.6.tar.gz
2.解压nginx压缩包
tar -zxvf nginx-1.21.6.tar.gz
3.进入nginx-1.21.6文件夹下
cd nginx-1.21.6
4.查看原版本nginx 的配置
/usr/local/nginx/sbin/nginx -V
[root@localhost nginx-1.21.6]# /usr/local/nginx/sbin/nginx -V
#nginx的版本
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled#nginx的配置信息
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre
5.配置新版nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre
6.编译
make
7.移走原先的nginx二进制文件
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old
8.替换新编译的文件到原nginx的sbin目录下
cp objs/nginx /usr/local/nginx/sbin/
9.执行升级命令(在解压出的新版本的nginx源文件目录下执行)
make upgrade
[root@localhost nginx-1.21.6]# make upgrade
/usr/local/nginx/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
kill -USR2cat /usr/local/nginx/logs/nginx.pid
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUITcat /usr/local/nginx/logs/nginx.pid.oldbin
10.查看是否升级成功
/usr/local/nginx/sbin/nginx -V
由原来的1.20.2已经升级到1.21.6
nginx version: nginx/1.21.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre
如果感觉这篇文章对您有帮助,可以给博主点赞、评论、收藏,这样是对博主最大的鼓励,谢谢。