nginx不僅可以隱藏版本信息,還支持自定義web服務(wù)器信息
先看看最終的隱藏結(jié)果吧
具體怎么實(shí)現(xiàn)呢,其實(shí)也很簡(jiǎn)單,請(qǐng)往下看
1 官網(wǎng)下載最新穩(wěn)定版
wget http://nginx.org/download/nginx-1.14.1.tar.gz
2 解壓
tar-xfnginx-1.14.1.tar.gz
cdnginx-1.14.1
3 修改C文件
(1)vim src/http/ngx_http_header_filter_module.c #修改49行
static u_char ngx_http_server_string[] = "Server: Please guess it!" CRLF; #Server后寫上你自定義的服務(wù)器信息

(2)vim src/http/ngx_http_special_response.c #修改36行
"<hr><center>Please guess it!</center>" CRLF #再寫一遍剛才的字符串
4 編譯配置
./configure --prefix=/usr/local/nginx
5 編譯安裝
?make && makeinstall
6 修改nginx配置文件,http節(jié)點(diǎn)下添加 server_tokens off
vim/usr/local/nginx/conf/nginx.conf
....
http{
server_tokensoff;
.....
7 啟動(dòng)nginx
/usr/local/nginx/sbin/nginx
8 測(cè)試
[root@node1 nginx-1.14.1]# curl -I http:
HTTP/1.1200 OK
Server: Please guess it!
Date: Wed, 07 Nov 201819:15:43 GMT
......
瀏覽器訪問測(cè)試
說明:(1)要是只想隱藏版本號(hào),而不想自定義服務(wù)器信息,不需要執(zhí)行第3步.
(2)要是對(duì)nginx升級(jí)同時(shí)還要做字符串自定義,也是沒有問題的,可以先修改C文件-->./configure --> make 即可
具體nginx升級(jí)請(qǐng)參考 https://www.cnblogs.com/Sunzz/p/9953443.html
鏈接:https://www.cnblogs.com/Sunzz/p/9962891.html
該文章在 2025/7/21 10:44:13 編輯過