首頁  >  文章  >  系統教程  >  在Linux和Unix上隱藏Nginx版本

在Linux和Unix上隱藏Nginx版本

WBOY
WBOY轉載
2024-02-09 19:50:29640瀏覽

使用 CLI 顯示目前 Nginx 版本

Nginx將在錯誤頁面和「伺服器」回應標頭欄位中顯示版本。我們可以使用以下命令進行驗證: 範例輸出:

$ curl -I https://your-domain
$ curl -I https://www.cyberciti.biz
HTTP/2 200 server: nginx/1.17.10 (Ubuntu)date: Tue, 23 Jun 2020 09:36:49 GMTcontent-type: text/html; charset=UTF-8strict-transport-security: max-age=15768000x-whome: l-ncbz01-mg-wg

這是我的HTTP / 502錯誤頁面顯示訊息的輸出:

在Linux和Unix上隱藏Nginx版本

使用server_tokens指令隱藏 Nginx 版本

您需要將server_tokens設定為 off 以隱藏 Linux 和類別 Unix 系統上的 Nginx 伺服器版本。使用文字編輯器(如 vim/nano)編輯您的 nginx.conf 檔案:

我們只能在 http、伺服器或位置上下文中設定server_tokens。我將添加到我的http部分:這是它的外觀:

$ sudo vim /etc/nginx/nginx.confserver_tokens off;
http {        ## Basic Settings ##        charset utf-8;        sendfile on;        tcp_nopush on;        tcp_nodelay on;        log_not_found off;        keepalive_timeout 65;        types_hash_max_size 2048;        client_max_body_size 16M;        include /etc/nginx/mime.types;        default_type application/octet-stream;        ## Hide Nginx version ##        server_tokens   off;        ## Security headers for Nginx ##         add_header Strict-Transport-Security "max-age=15768000" always;        add_header X-Content-Type-Options "nosniff" always;        add_header X-Frame-Options "SAMEORIGIN" always;        add_header X-Xss-Protection "1; mode=block" always;        add_header Referrer-Policy  strict-origin-when-cross-origin;        add_header Feature-policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'";        add_header Content-Security-Policy   "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;        ## SSL Settings ##        ssl_protocols TLSv1.3;        access_log /var/log/nginx/access.log;        error_log /var/log/nginx/error.log;        ## Virtual Host Configs ##        include /etc/nginx/conf.d/*.conf;        include /etc/nginx/sites-enabled/*;}

正常重新啟動或重新載入 Nginx 伺服器:

#
sudo nginx -tsudo nginx -s reload

驗證 Nginx 版本是否隱藏

使用 curl 指令,如下所示:看我的 Nginx 伺服器沒有顯示任何版本:

$ curl -I https://your-domain-name-here
$ curl -I https://www.cyberciti.biz

HTTP/2 200 server: nginxdate: Tue, 23 Jun 2020 09:43:17 GMTcontent-type: text/html; charset=UTF-8strict-transport-security: max-age=15768000

Firefox 也確認我也成功隱藏了 Nginx 版本:

在Linux和Unix上隱藏Nginx版本

#隱藏 Nginx 版本的其他可能值

#語法如下:在Linux,*BSD和Unix上的預設值如下:

server_tokens on | off | build | string;
server_tokens on;

從伺服器標頭和錯誤頁中刪除版本

我們可以更改為以下值來啟用或停用發出 nginx 版本:
on:顯示版本號。
off:關閉顯示版本號。
build:確保我們發出一個建置名稱以及nginx版本。您必須擁有 Nginx 版本 1.11.10。
string:僅適用於商業訂閱,從版本 1.9.13 開始,可以使用帶有變數的字串顯示設定錯誤頁面上的簽章和「伺服器」回應標頭欄位值。空字串禁用“伺服器”欄位的發出。

在 Nginx 中設定自訂版本號碼

#例如,商業訂閱(Nginx Plus)使用者可以將其設定為偽造的伺服器版本和自訂名稱: 使用服務命令或systemctl命令重新載入Nginx伺服器: 同樣,使用curl 命令對其進行測試,如下所示:

;$ service nginx reload$ curl -I http://127.0.0.1/
在Linux和Unix上隱藏Nginx版本

隱藏版本是默默無聞的安全性

#是的,它是透過隱藏功能的安全性。它是縱深防禦的方法之一。但是,它不應該是主要的防禦形式。您需要編寫安全程式碼。安裝防火牆,尤其是 WAF(Web 應用程式防火牆)。沒有理由揭露Nginx或PHP或Python版本,因為它對攻擊者可能是有用的信息。請記住,Linux / Unix作業系統,Web apps / Nginx應該保持安全,無論Nginx版本是否公開。但是,我們不會透過發布版本號來為攻擊者帶來任何好處。

以上是在Linux和Unix上隱藏Nginx版本的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:lxlinux.net。如有侵權,請聯絡admin@php.cn刪除