如何为容器的 Azure 应用服务添加安全性 headers

How add security headers to azure app service for containers

当部署为 docker 容器 (linux) 时,我在寻找如何将自定义 http 安全性 headers(如 HSTS)添加到 Azure 应用程序服务方面取得了有限的成功。我不确定这是否可以直接在应用程序服务上实现,或者是否需要应用程序网关之类的东西。

如果使用 kubernetes 或 swarm,我可以在反向代理入口上执行此操作,但我如何在应用服务上执行此操作?

2 个解决方案:

  1. 转到 Azure 门户并在 :

Your Function App -> Platform Features -> Custom Domain and set HTTPS Only to the desired value (On).

  1. 将此添加到 web.config
<outboundRules>
 <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
     <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
                <conditions>
                    <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                </conditions>
                <action type="Rewrite" value="max-age=31536000" />
    </rule>
</outboundRules>