设置 Strict-Transport-Security header

你好,

我想修改 Strict-Transport-Security 标头。我在 app.yml 中使用了以下代码:

run:  
# nginx modifications
  - replace:       
      filename: "/etc/nginx/conf.d/discourse.conf"       
      from: /add_header Strict-Transport-Security.+/       
      to: "add_header Strict-Transport-Security 'max-age=31536000; includeSubdomains; preload';"

这可以处理第一次出现的情况:
add_header Strict-Transport-Security 'max-age=63072000';

但还有另一个出现的情况是:

location @discourse {
add_header Strict-Transport-Security 'max-age=31536000'; # remember the certificate for a year and automatically connect to HTTPS for this domain

我是否做错了什么?为什么 Strict-Transport-Security 标头的第二次出现没有被修改?

我已经测试了几种自定义方法。只有第一次出现的

add_header Strict-Transport-Security

被替换了。有什么方法可以做到这一点吗?

您需要在 replace 命令参数中添加 global: true

1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.