【问题标题】:nginx: Remove "Server" response header - not honour what said in doconginx:删除“服务器”响应标头-不尊重 doco 中所说的内容
【发布时间】:2020-07-19 02:52:11
【问题描述】:

Nginx 版本:1.15.8

根据 nginx 文档: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;”直接完成的版本;

有人用这种方式工作吗?欢迎提出意见和建议。

谢谢,

【问题讨论】:

    标签: nginx


    【解决方案1】:

    此外,作为我们商业订阅的一部分,从版本 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

    【讨论】:

    • 谢谢,缺少“商业订阅”部分
    【解决方案2】:

    在http指令中使用以下,更正确(来自'Synopsis'下的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,似乎已被弃用。

    【讨论】:

      猜你喜欢
      • 2020-11-05
      • 1970-01-01
      • 2017-07-11
      • 2010-11-13
      • 2014-11-06
      • 2021-06-22
      • 2017-09-17
      • 2016-05-09
      • 2021-12-03
      相关资源
      最近更新 更多