Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Nginx 隱藏版本號完整指南:提升 Web 伺服器資安等級

編輯:關於伺服器

為什麼要隱藏 Nginx 版本號?

預設回應標頭 Server: nginx/1.18.0 會洩露確切版本。攻擊者可針對已知該版本漏洞(如 CVE-2013-2028、CVE-2017-7529)發起精準攻擊。隱藏版本號屬於資安「最小資訊揭露」原則的基本實踐。

步驟一:修改 nginx.conf 關閉 server_tokens

vi /etc/nginx/nginx.conf

在 http { } 區塊內加入:

http {
    ...
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 60;
    tcp_nodelay on;
    server_tokens off;
    ...
}

步驟二:修正 FastCGI 傳遞的 SERVER_SOFTWARE

編輯 fastcgi.conf 或 fcgi.conf(視安裝路徑而定):

# 原設定
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

# 修改為
fastcgi_param SERVER_SOFTWARE nginx;

避免 PHP 錯誤頁面、phpinfo() 等洩露版本。

步驟三:重新載入配置生效

nginx -t && systemctl reload nginx

或傳統方式:/etc/init.d/nginx reload

驗證結果

curl -I https://your.domain.com

預期輸出:

HTTP/1.1 200 OK
Server: nginx
Date: ...
Content-Type: text/html
...

僅顯示 nginx,無版本號。404/50x 錯誤頁亦同。

進階:自定義 Server 標頭(可選)

若需完全偽裝,可編譯 Nginx 時使用 --with-http_headers_more_module 並設定:

more_set_headers 'Server: MyWebServer';

瀏覽器外掛驗證

Firefox 「Wappalyzer」、「BuiltWith」等工具同樣無法偵測版本,因它們同樣依賴 HTTP 標頭偵測。

Copyright © Windows教程網 All Rights Reserved