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文件是否生效(截圖忘記截了)

1 kill -WINCH `cat /home/ljy/app/nginx/nginx.pid.oldbin` 2 kill -QUIT `cat /home/ljy/app/nginx/nginx.pid.oldbin`


二、nginx-1.18.0修改缺省banner信息
參考鏈接:https://blog.csdn.net/yuanzhenwei521/article/details/78819482

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
未改之前寫的是: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
5、測試驗證