大家好,
对于我们当前的自托管 Discourse 实例,我们需要在 STS 标头中添加“IncludeSubDomains”,因为这是我们内部扫描仪的要求。
以前,我通过在构建后的 app.yml 的自定义命令中使用 sed 命令来实现此目的,以更新 /etc/nginx/conf.d/discourse.conf 以包含 'add_header Strict-Transport-Security “max-age=31536000; includeSubDomains” always;
以及:
- replace:
filename: "/etc/nginx/conf.d/outlets/discourse/20-https.conf"
from: /add_header Strict-Transport-Security.+/
to: add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
global: true
- replace:
filename: "/etc/nginx/conf.d/outlets/server/20-https.conf"
from: /add_header Strict-Transport-Security.+/
to: add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
global: true
这以前是有效的。但是,它现在停止工作了。我读到创建一个新的 outlet 文件应该允许我使用以下方法添加此内容:
hooks:
after_code:
- file:
path: /etc/nginx/conf.d/outlets/server/90-hsts.conf
chmod: 444
contents: |
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
然而,这导致存在两个 STS 标头(一个来自 SSL 模板,一个来自我的新模板)。是否有更好的方法可以避免出现两个 STS 标头?我原以为 nginx 会尊重最后添加的标头,并忽略仅包含 max-age=31536000; 的 SSL 模板标头,所以这是个缺陷吗?感谢您提供的任何指导。