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、測試驗證

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM