首頁  >  文章  >  運維  >  nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決

nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決

WBOY
WBOY轉載
2023-05-21 09:13:051600瀏覽

nginx不僅可以隱藏版本訊息,還支援自訂web伺服器資訊

先看看最終的隱藏結果吧

nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決

##具體怎麼實現呢,其實也很簡單,請往下看

1 官網下載最新穩定版

wget http://nginx.org/download/nginx-1.14.1.tar.gz

2 解壓縮

tar -xf nginx-1.14.1.tar.gzcd nginx-1.14.1

3 修改c檔


#(1)vim src/http/ngx_http_header_filter_module.c            #修改49行


static u_char ngx_http_server_string [39行

static u_char ngx_http_server_string]> 上寫完後寫[pleases -pleases ngx_http_server_string]> 上寫後[表> )> 上後。自訂的伺服器資訊


nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決


(2)vim src/http/ngx_http_special_response.c   #修改36行
"
please guess it!
" crlf   #再寫一遍剛​​才的字串

nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決

4 編譯設定

./configure --prefix=/usr/local/nginx

5 編譯安裝

make && make install

6 修改nginx設定檔,http節點下新增server_tokens off

nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決

vim /usr/local/nginx/conf/nginx.conf
....
http {
server_tokens off;
.....

7 啟動nginx

#
/usr/local/nginx/sbin/nginx

8 測試

[root@node1 nginx-1.14.1]# curl -i http://127.0.0.1 http/1.1 200 ok server: please guess it! date: wed, 07 nov 2018 19:15:43 gmt
  ......

瀏覽器存取測試

nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決

#  

說明:

(1)如果只想隱藏版本號,而不想自訂伺服器信息,不需要執行第3步.  

###(2)要是對nginx升級同時還要做字符串自定義,也是沒有問題的,可以先修改c文件- ->./configure --> make 即可###

以上是nginx隱藏版本號碼與WEB伺服器資訊問題怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除