me小怪兽

导航

nginx版本升级(源码)

根据漏扫报告显示nginx版本低,需要升级到高版本,记录下升级步骤,希望可以帮助到大家。

操作系统:centos7.9

nginx版本:1.16.1 升级到1.20.2

nginx安装路径:/home/nginx

1、参数确认,升级版本的时候参数和之前的保持一致

[root@nginx ]# /home/nginx/sbin/nginx -V
nginx version: nginx/1.16.1    #版本1.16.1
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=/home/nginx --with-poll_module --with-http_ssl_module --with-http_stub_status_module --with-stream --with-pcre

2、上传,解压新版本

[root@nginx ~]# tar zxf nginx-1.20.2.tar.gz
[root@nginx ~]# cd nginx-1.20.2/

3、使用先前参数进行编译

[root@nginx nginx-1.20.2]# ./configure --prefix=/home/nginx --with-poll_module --with-http_ssl_module --with-http_stub_status_module --with-stream --with-pcre

Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library

nginx path prefix: "/home/nginx"
nginx binary file: "/home/nginx/sbin/nginx"
nginx modules path: "/home/nginx/modules"
nginx configuration prefix: "/home/nginx/conf"
nginx configuration file: "/home/nginx/conf/nginx.conf"
nginx pid file: "/home/nginx/logs/nginx.pid"
nginx error log file: "/home/nginx/logs/error.log"
nginx http access log file: "/home/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

4、  make 编译(切记只能make 不要make install会覆盖之前安装的nginx)

[root@nginx nginx-1.20.2]# make

  make完成后会在到当前目录生成一个objs文件夹,里面有一个nginx执行文件将此文件覆盖到之前编译nginx的sbin目录直接替换即可

[root@nginx nginx-1.20.2]# ll objs/
总用量 7116
-rw-r--r-- 1 root root   17954 9月   9 14:07 autoconf.err
-rw-r--r-- 1 root root   49260 9月   9 14:07 Makefile
-rwxr-xr-x 1 root root 7082192 9月   9 14:08 nginx
-rw-r--r-- 1 root root    5517 9月   9 14:08 nginx.8
-rw-r--r-- 1 root root    7391 9月   9 14:07 ngx_auto_config.h
-rw-r--r-- 1 root root     657 9月   9 14:07 ngx_auto_headers.h
-rw-r--r-- 1 root root    8214 9月   9 14:07 ngx_modules.c
-rw-r--r-- 1 root root   91592 9月   9 14:08 ngx_modules.o
drwxr-xr-x 9 root root      91 9月   9 14:07 src

5、备份,替换先前版本的nginx启动文件

[root@nginx nginx-1.20.2]# mv /home/nginx/sbin/nginx /home/nginx/sbin/nginx_old
[root@nginx nginx-1.20.2]# cp objs/nginx /home/nginx/sbin/

6、重启nginx

[root@nginx nginx-1.20.2]# systemctl restart nginx.service

7、查看现nginx版本

[root@nginx nginx-1.20.2]# /home/nginx/sbin/nginx -V
nginx version: nginx/1.20.2    #版本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=/home/nginx --with-poll_module --with-http_ssl_module --with-http_stub_status_module --with-stream --with-pcre

 

如果是yum安装的nginx,直接yum update nginx 就可以了。

posted on 2022-09-09 14:22  me小怪兽  阅读(801)  评论(0编辑  收藏  举报