nginx:删除“服务器”响应标头-不遵守doco

时间:2019-05-28 00:51:49

标签: nginx

Nginx版本:1.15.8

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

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

但是当我放入这个

server_tokens '';

它抱怨:

nginx: [emerg] invalid value "" 

也尝试过:

server_tokens "";
server_tokens;

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

有人用这种方式工作吗?欢迎发表评论和建议。

谢谢

2 个答案:

答案 0 :(得分:0)

  

此外,作为我们的 商业订阅 的一部分,从1.9.13版开始,可以显式设置错误页面上的签名和“服务器”响应标头字段值使用带变量的字符串。空字符串将禁用“服务器”字段的发射。

来源:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens

它需要商业订阅。

否则,请安装ngx_headers_more模块。

并将以下内容添加到您的nginx conf中,然后重新启动nginx。这将删除“服务器”标头。 -

more_clear_headers  "Server";
more_clear_headers  "server";

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

答案 1 :(得分:0)

在http指令中使用以下内容,它是更正确的(来自“提要”下的official readme

more_set_headers 'Server: some string';

为他人提供更完整的答案。 如果您使用的是nginx商业版,则可以在http指令中使用以下命令:(http core module docs

server_tokens 'string';

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

这不适用于modsecurity v3,似乎已弃用。