一、说明

nginx有时安装的时候会不默认安装一些以后需要的模块,比如代理数据库端口所需的--with-stream,以此为例

先查看本地nginx版本,选择相同版本的安装包进行编译,可以看见并没有添加--with-stream模块

[root@test1 nginx-1.20.2]# /usr/local/nginx/sbin/nginx -V
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
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

二、编译替换

到官方网站上下载当前安装版本的nginx,并解压后进行编译

[root@test1 soft]# tar -zxf nginx-1.20.2.tar.gz 
[root@test1 soft]# ls
Centos7.iso  nginx-1.20.2  nginx-1.20.2.tar.gz
[root@test1 soft]# cd nginx-1.20.2/
[root@test1 nginx-1.20.2]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock  --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-stream

注意下一位make,不用make install,否则就是直接重装了。

make

make完毕会在当前安装包目录下的objs目录下生成新的nginx二进制文件

备份原来的nginx,然后复制新的nginx文件只安装目录进行替换

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak

[root@test1 nginx-1.20.2]# cd objs/
[root@test1 objs]# ls
autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
[root@test1 objs]# cp -f nginx /usr/local/nginx/sbin/nginx
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y

替换完成进行正确性检查(可选)

/usr/local/nginx/sbin/nginx -t

按需修改文件,并reload

/usr/local/nginx/sbin/nginx -s reload

查看新的模块配置是否完成

[root@test1 sbin]# ./nginx -V
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
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-stream

三、其他可选操作

直接关了再开

/usr/local/nginx/sbin/nginx stop
/usr/local/nginx/sbin/nginx start

如果配置的有service,可以直接

service nginx restart

 

posted on 2022-09-23 15:19  牛肉丨火锅  阅读(619)  评论(0编辑  收藏  举报