【问题标题】:nginx sends duplicate headernginx 发送重复的标头
【发布时间】:2018-12-15 20:55:05
【问题描述】:

在我的 nginx.conf 文件中,我在 http 级别定义了一个标头

add_header Strict-Transport-Security "max-age=86400; includeSubDomains" always;

当我在 chrome 开发工具中检查网络响应标头时,它会显示其中 2 个标头

strict-transport-security: max-age=15552000; includeSubDomains
strict-transport-security: max-age=86400; includeSubDomains

注意事项:

  • 在我的配置文件中,我只使用了一次add_header
  • 我也没有包含指令
  • 我在 nginx-docker 镜像中找不到另一个 nginx.conf 文件

问题:

  • 知道第二个标题的来源吗?
    即一些默认值或从另一个配置文件继承)
  • 也许知道如何调试它?

【问题讨论】:

  • 不要使用浏览器,而应该使用curl -I ...来调试服务器。命令nginx -T 将显示整个配置。如果此服务器正在与上游服务(例如 PHP)通信,则应用程序也可能提供标头。

标签: nginx nginx-config


【解决方案1】:

感谢@RichardSmith 的精彩评论。

  • nginx -T 非常适合测试,因为它会显示完整配置(包括所有包含等)
  • curl -I 还显示了两个标题(以确保浏览器不使用任何缓存等)
  • 实际上第二个标头是从上游服务器发送的 - 然后 nginx 添加了我在nginx.conf 中定义的标头

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 2013-06-12
    • 2013-04-04
    • 1970-01-01
    • 2011-07-04
    • 2015-06-17
    • 1970-01-01
    相关资源
    最近更新 更多