參考:
https://www.cnblogs.com/lsdb/p/6894665.html Nginx隐藏版本号操作
https://jingyan.baidu.com/article/1709ad805b074c4635c4f041.html 如何更改nginx的源碼以及版本号
https://blog.csdn.net/leiwuhen92/article/details/104405674 檢視nginx版本号的幾種方法
一、為什麼要隐藏nginx版本号:
Nginx預設顯示版 本 号,但這樣人家能看到你的伺服器nginx的真實版本号,而這個暴露出的版本号很易變成攻擊者可利用的資訊。是以,從安全的角度來說, 隐藏版本号會相對安全些!
二、隐藏nginx版本号的方法:
1、在nginx.conf配置檔案中的http子產品中國添加“ server_tokens off;”
2、編輯配置檔案fastcgi.conf 和 fastcgi_params 此法嘗試沒成功
2.1、修改nginx.conf:
修改内容: http { include /etc/nginx/mime.types; default_type application/octet-stream; server_tokens off; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
結果 : curl查不到nginx的版本号,postman請求看不到nginx版本号,但使用nginx -v依舊可以查到 [[email protected] nginx]# curl -i 127.0.0.1 HTTP/1.1 200 OK Server: nginx #nginx版本号被隐藏了 Date: Thu, 20 Feb 2020 02:19:35 GMT Content-Type: text/html [[email protected] nginx]# nginx -v nginx version: nginx/1.16.1
2.2、編輯配置檔案fastcgi.conf 和 fastcgi_params:
修改内容: fastcgi_param SERVER_SOFTWARE nginx/$nginx_version ; 結果 :沒生效
三、修改nginx版本号
修改nginx版本号需要在配置安裝nginx之前進行。下載下傳完成nginx并解壓後,首先要 對源碼進行修改,源碼檔案都在二級目錄“nginx-0.8.53/src/”下,找到如下檔案“src/core/nginx.h”,然後再對它進行修改。 1、修改第一個檔案src/core/nginx.h
[[email protected] nginx-0.8.53]# vi src/core/nginx.h
2、修改第二個檔案/src/http/ngx_http_header_filter_module.c,将末尾的nginx修改為OWS
3、修改第三個檔案/src/http/ngx_http_special_response.c
4、檢查文法重新啟動
nginx -t nginx -s reload
5、校驗:輸入錯誤位址,看是否隐藏