1、首先需要查看当前安装的 Nginx 的版本号和编译选项,使用命令 nginx -V
可以查看。
#查询nginx已安装模块
[root@test sbin]# ./nginx -V
nginx version: nginx/1.19.9
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: --with-http_ssl_module
configure arguments已安装的模块:可以看出编译安装使用了----with-http_ssl_module
2、加入需要安装的模块(--with-http_gzip_static_module),重新编译
#检查是否还有保留nginx的源码目录,没有就去官网下载对应的nginx版本进行解压
#进入nginx源码安装目录,执行以下命令(历史已安装模块加新增模块)
[root@test nginx-1.19.9]# ./configure --with-http_gzip_static_module --with-http_ssl_module
#千万千万不能 make install ;否则会把之前已经安装的nginx 覆盖掉
[root@test nginx-1.19.9]# make
#找到历史nginx二级制文件,备份原有已安装好的nginx,防止新的nginx二级制文件出现问题
[root@test nginx-1.19.9]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#把新的nginx程序覆盖旧的
[root@test nginx-1.19.9]# cp -rfp objs/nginx /usr/local/nginx/sbin/
#重启nginx
[root@test nginx]# /usr/local/nginx/sbin/nginx
#验证
[root@test nginx-1.19.9]# nginx -V
nginx version: nginx/1.19.9
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: --with-http_gzip_static_module --with-http_ssl_module