24资源网

24资源分享网,分享资源,收集整理资源,有态度的分享资源网

默认值,查询HTTP头或Nginx服务器产生的错误时显示的Nginx版本。本快速指南解释了如何在不重新启动系统的情况下隐藏或删除Linux或Unix服务器上的Nginx版本。

使用 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错误页面显示信息的输出:

使用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 版本:

隐藏 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/

隐藏版本是默默无闻的安全

是的,它是通过隐蔽功能的安全性。它是纵深防御的方法之一。但是,它不应该是主要的防御形式。您需要编写安全代码。安装防火墙,尤其是 WAF(Web 应用程序防火墙)。没有理由暴露Nginx或PHP或Python版本,因为它对攻击者可能是有用的信息。请记住,Linux / Unix操作系统,Web apps / Nginx应该保持安全,无论Nginx版本是否公开。但是,我们不会通过发布版本号来给攻击者带来任何好处。

举报/反馈

               
发表评论