Server头暴漏服务器类型和版本号

使用Nginx作为代理服务器的话,默认会在Response Header Server中显示nginx与版本号,这样可能会让别用用心的人,利用已知版本漏洞攻击。
image-1686129158851

原生Nginx解决

隐藏版本号

修改nginx.conf,在http中添加如下配置,即可隐藏版本信息

http
    {
        #其他配置省略...
        server_tokens off;
        #其他配置省略...
}

修改后显示如下

image-1686129829550

隐藏服务器类型信息

通过原生的nginx隐藏服务器类型信息需要修改源码文件,重新编译安装。笔者不是很推荐,这里就赘述了,想要通过这种方式的同学,可以自行研究。

OpenResty解决

帮我们提供了headers-more-nginx-module模块,方便我们在Nginx http服务器中添加、设置、删除任意头信息。配置的位置也较为灵活,可以放置在一下位置,只是影响的粒度不同。

http
    {
        #其他配置省略...
        more_set_headers "Server: Bobby'Server";
        #其他配置省略...
}
server
{
    listen 80;
		listen 443 ssl http2;
    server_name www.caofanqi.cn;
    #其他配置省略...
    more_set_headers "Server: Bobby'Server";
    #其他配置省略...
}
server
{
    listen 80;
		listen 443 ssl http2;
    server_name www.caofanqi.cn;
    
    #其他配置省略...
    
    location / {
    #其他配置省略...
    more_set_headers "Server: Bobby'Server";
    proxy_pass http://your-ip:your-port/;
  }
    
    #其他配置省略...
}

调整后效果

image-1686131186006

headers-more-nginx-module模块提供的功能还有很多,感兴趣的小伙伴,可以通过下面参考资料的链接地址进行查看。



参考资料:
http://openresty.org/cn
https://github.com/openresty/headers-more-nginx-module#more_set_headers