預設回應標頭 Server: nginx/1.18.0 暴露確切版本,攻擊者可針對已知 CVE (如 CVE-2013-2028、CVE-2017-7529) 發動精準攻擊。
curl -I https://your-domain.com
# HTTP/1.1 200 OK
# Server: nginx/1.18.0 ← 洩露版本
http {
...
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off; # 關鍵:隱藏所有錯誤頁面與標頭版本
...
}
# 原設定
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
# 修改為
fastcgi_param SERVER_SOFTWARE nginx;

nginx -t # 語法檢查
nginx -s reload # 平滑重載
curl -I https://your-domain.com
# Server: nginx ← 僅顯示名稱,無版本號

server_tokens off; 同時隱藏 404/50x 等錯誤頁面底部的版本資訊,達到完全隱藏。