使用 CURL 指令,可以從伺服器的回應中看到 nginx 的版本是 1.26.2
在弱點掃描時會出現 Version Disclosure (Nginx) 風險,我們可以透過修改 Nginx 的設定檔來隱藏 Nginx 版本號碼。
編輯 Nginx 設定檔:
增加 server_tokens 設定值來停止顯示版本號碼:
檢查設定檔是否正確:
重新讀取/套用設定檔:
再次使用 CURL 指令,就會發現看不到版號了:
curl -I http://localhost:80
HTTP/1.1 301 Moved Permanently
Server: nginx/1.26.2
Date: Mon, 20 Jan 2025 10:54:11 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://localhost:80/
在弱點掃描時會出現 Version Disclosure (Nginx) 風險,我們可以透過修改 Nginx 的設定檔來隱藏 Nginx 版本號碼。
編輯 Nginx 設定檔:
sudo vi /etc/nginx/nginx.conf
增加 server_tokens 設定值來停止顯示版本號碼:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
檢查設定檔是否正確:
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重新讀取/套用設定檔:
sudo systemctl reload nginx
再次使用 CURL 指令,就會發現看不到版號了:
curl -I http://localhost:80
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 20 Jan 2025 10:56:05 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive
Location: https://localhost:80/
留言
張貼留言
如果有任何問題、建議、想說的話或文章題目推薦,都歡迎留言或來信: a@ruyut.com