nginx:删除“Server”响应头 - 不遵循文档中的说明

4

Nginx版本:1.15.8

根据nginx文档:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens

"从版本1.9.13开始,可以使用带有变量的字符串显式设置错误页面上的签名和“Server”响应头字段值。空字符串禁用“Server”字段的发射。"

但是当我输入以下内容时:

server_tokens '';

它抱怨:

nginx: [emerg] invalid value "" 

还尝试过:

server_tokens "";

server_tokens;

它们都不起作用。请注意,我想完全删除“服务器”标头,而不仅仅是版本,这可以通过“server_tokens off;”直接完成

有人以这种方式使用吗?欢迎评论和建议。

谢谢。

2个回答

8
此外,在我们的商业订阅中,从版本1.9.13开始,可以使用带有变量的字符串显式设置错误页面上的签名和“Server”响应头字段值。空字符串禁用了“Server”字段的发射。
来源:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens 需要商业订阅。
否则,请安装ngx_headers_more模块。
然后将以下内容添加到您的Nginx配置文件中,并重新启动Nginx。这将删除“server”标头。
more_clear_headers  "Server";
more_clear_headers  "server";

安装:https://github.com/openresty/headers-more-nginx-module#installation


1
谢谢,我漏掉了“商业订阅”这一部分。 - tuan.dinh

0

在http指令中使用以下内容,这是更正确的方法(来自官方自述文件下的“概要”)

more_set_headers 'Server: some string';

对于其他人的更完整的答案。 如果您正在使用nginx商业版本,则可以在http指令中使用以下内容:(http核心模块文档

server_tokens 'string';

如果使用modsecurity v2-2.9,则可以将以下内容添加到相关的modsecurity conf文件中:SecServerSignature String

这对于modsecurity v3不起作用,似乎已被弃用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接