本站使用了 Pjax 等基于 JavaScript 的开发技术,但您的浏览器已禁用 JavaScript,请开启 JavaScript 以保证网站正常显示!

Nginx升级指北

准备工作

查看当前Nginx版本

[root@test-ds-nginx ~]# nginx -v
nginx version: nginx/1.12.2

查看并备份当前版本Nginx编译配置

[root@test-ds-nginx ~]# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
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 --user=nginx --group=nginx --pid-path=/var/run/nginx/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/usr/local/nginx/temp/proxy --http-fastcgi-temp-path=/usr/local/nginx/temp/fcgi --lock-path=/var/run/nginx/nginx.lock --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_flv_module --with-debug

升级Nginx

获取Nginx

[root@test-ds-nginx ~]# cd /usr/src/
[root@test-ds-nginx src]# wget https://nginx.org/download/nginx-1.14.2.tar.gz
[root@test-ds-nginx src]# tar xf nginx-1.14.2.tar.gz

修改源文件,隐藏版本号

[root@test-ds-nginx src]# cd nginx-1.14.2
[root@test-ds-nginx nginx-1.14.2]# vim src/core/nginx.h
Line 14:
#define NGINX_VER          "nginx/" NGINX_VERSION

修改为

#define NGINX_VER          "Linux_Web_Server/" NGINX_VERSION /*modify this line*/

重新编译,切勿make install,否则将覆盖安装!

[root@test-ds-nginx nginx-1.14.2]# ./configure  --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --user=nginx --group=nginx --pid-path=/var/run/nginx/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/usr/local/nginx/temp/proxy --http-fastcgi-temp-path=/usr/local/nginx/temp/fcgi --lock-path=/var/run/nginx/nginx.lock --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_flv_module --with-debug
[root@test-ds-nginx nginx-1.14.2]# make -j4

备份旧的Nginx执行程序及安装路径

[root@test-ds-nginx nginx-1.14.2]# service nginx stop
[root@test-ds-nginx nginx-1.14.2]# tar czvf /usr/local/nginx.bak.tar.gz /usr/local/nginx/
[root@test-ds-nginx nginx-1.14.2]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old #备份旧的Nginx执行程序

将新编译的Nginx执行程序拷贝到现有Nginx执行程序目录中

[root@test-ds-nginx nginx-1.14.2]# cp objs/nginx /usr/local/nginx/sbin/nginx

重新启动

[root@test-ds-nginx nginx-1.14.2]# service nginx start
正在启动 nginx:                                           [确定]

检查是否升级成功

[root@test-ds-nginx nginx-1.14.2]# nginx -v
nginx version: Linux_Web_Server/1.14.2

 继续浏览关于 Nginx 的文章

 本文最后更新于 2019/04/19 08:21:18,可能因经年累月而与现状有所差异

 引用转载请注明:数字漩涡 > Web > Nginx升级指北

发现共鸣

如是说:请成为永远疯狂 ,永远浪漫 ,永远清澈的存在。