預設回應標頭 Server: nginx/1.18.0 會洩露確切版本。攻擊者可針對已知該版本漏洞(如 CVE-2013-2028、CVE-2017-7529)發起精準攻擊。隱藏版本號屬於資安「最小資訊揭露」原則的基本實踐。
vi /etc/nginx/nginx.conf
在 http { } 區塊內加入:
http {
...
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
...
}
編輯 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 錯誤頁亦同。
若需完全偽裝,可編譯 Nginx 時使用 --with-http_headers_more_module 並設定:
more_set_headers 'Server: MyWebServer';
Firefox 「Wappalyzer」、「BuiltWith」等工具同樣無法偵測版本,因它們同樣依賴 HTTP 標頭偵測。