nginx平滑升级及隐藏服务器banner信息

nginx平滑升级及隐藏服务器banner信息

  今天大年初一,还是兢兢业业写篇博客 ~~~

  本文主要讲的是:

  【i】nginx从1.13.3平滑升级到1.16.0。(为啥要升级呀,因为被爆出旧版本nginx漏洞)

    【ii】nginx1.18.0版本隐藏服务器banner信息(也是因为被爆出旧版本nginx漏洞,才升级1.18.0,然后这个隐藏banner信息是xx项目等保低风险项查出来的,上级领导要求搞)

  最近写的频繁,有人说我要保质保量(3月前写够400篇),所以我就尽量丰富呗,不然一篇拆两篇,你懂滴,哈哈哈哈。。。。

 

一、nginx从1.13.3平滑升级到1.16.0

1、查看当前nginx版本,及相关编译参数

/home/ljy/app/nginx/sbin/nginx -V
nginx version: nginx
/1.13.3 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --user=ljy --group=ljy --prefix=/home/ljy/app/nginx --with-stream --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-pcre

 

2、下载nginx-1.16.0二进制包并解压

cd /usr/local/src
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -xvf nginx-1.16.0.tar.gz

 

3、备份旧nginx重要文件

(1)备份旧nginx启动管理终端命令

cp /home/ljy/app/nginx/sbin/nginx /tmp/

(2)备份旧nginx配置文件

前提:先把整个conf目录压缩成 conf_0620.tar.gz

cp /home/ljy/app/nginx/conf_0620.tar.gz /tmp/

 

4、编译nginx-1.16.0

跟第1条查看nginx-1.13.3的编译参数一样的

cd /usr/local/src/nginx-1.16.0
./configure --user=ljy --group=ljy --prefix=/home/ljy/app/nginx --with-stream --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-pcre

make #对源代码进行编译,注意下面不要运行:make install !!!

 可以看到  /home/ljy/app/nginx/   安装了新版本nginx-1.16.0相关目录和文件

 

5、备份原来二进制nginx,并替换为新的

(再备份一次,以防万一,当然不做也行)

mv /home/ljy/app/nginx/sbin/nginx /home/ljy/app/nginx/sbin/nginx_bak
cp /usr/local/src/nginx-1.16.0/objs/nginx /home/ljy/app/nginx/sbin/nginx

 

6、测试一下复制过来的二进制nginx文件是否生效(截图忘记截了)

/home/ljy/app/nginx/sbin/nginx -t

 
7、发送USR2信号给nginx master 进程
kill -USR2 `cat /home/ljy/app/nginx/nginx.pid`
 
这句话是网上抄的:
nginx服务接收到USR2信号后,首先会将旧的nginx.pid文件添加后缀.oldbin,变为nginx.pid.oldbin,然后执行新版本的二进制文件启动服务,如果新的服务启动成功,系统中将有新旧两个Nginx服务共同提供web服务
 
这关键的图我截下来啦,不然大家肯定会觉得没信服力
新旧两个nginx提供服务,旧nginx的进程号是28120(cat /home/ljy/app/nginx/nginx.pid)

 

8、测试验证

ls /home/ljy/app/nginx/ -l |grep nginx
6月13日是旧版本的nginx

 

9、通过发送WINCH信号(平缓停止worker process)和QUIT信号(平缓停止Nginx服务)停止旧的Nginx服务进程
1 kill -WINCH `cat /home/ljy/app/nginx/nginx.pid.oldbin`
2 kill -QUIT `cat /home/ljy/app/nginx/nginx.pid.oldbin`

只剩下新版本nginx-1.16.0了

 

10、验证测试
/home/ljy/app/nginx/sbin/nginx -V

 

 

二、nginx-1.18.0修改缺省banner信息

参考链接:https://blog.csdn.net/yuanzhenwei521/article/details/78819482

未修复之前显示:Tengine

 

 

改源码重新编译
1、vim /usr/local/src/nginx-1.18.0/src/http/ngx_http_header_filter_module.c
 修改这堆:
原来:
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;



改成:
static u_char ngx_http_server_string[] = "Server: hart-edu" CRLF;
static u_char ngx_http_server_full_string[] = "Server: unkowna" CRLF;
static u_char ngx_http_server_build_string[] = "Server: unkowna" CRLF;

 2、vim /usr/local/src/nginx-1.18.0/src/core/nginx.h

13 #define NGINX_VERSION      "1.18.0"
改成:  
    #define NGINX_VERSION      "0.0.1"

 

3、vim /usr/local/src/nginx-1.18.0/src/http/ngx_http_special_response.c   

36行

 

未改之前写的是:nginx

 

4、重新编译安装nginx-1.18.0

cd /usr/local/src/nginx-1.18.0
./configure --prefix=/home/ljy/app/nginx18 --user=ljy --group=ljy --with-pcre --with-http_ssl_module --with-http_stub_status_module --with-openssl=/usr/local/openssl
 make
 make install

 

5、测试验证

 

 

 

 

posted @ 2021-02-12 11:55  windysai  阅读(2443)  评论(0编辑  收藏  举报