deekayen.iis_custom_headers

IIS 自定义头

CI 平台 项目状态:不活跃 - 项目已达到稳定可用状态,但不再积极开发;支持/维护将根据时间情况提供。

在 Microsoft Windows Server 上的 IIS 网站中添加或移除全局自定义 HTTP 头。

角色变量

iis_custom_headers 默认变量定义了自定义 HTTP 头的键和值。如果您希望重写它,您需要重新定义所有应该是 presentabsent 的头。Ansible 不会将您重写的变量与默认值合并。X-Frame-Options 头由 IETF 在 RFC7034 中定义,以提高 web 应用程序的安全性。

默认情况下,Ansible 在任务结束时会重启 IIS,因为它通常假设 win_shell 执行导致了更改;切换 iis_custom_headers_restart_iis 以防止 IIS 重启。

iis_custom_headers:
  - { name: "X-Frame-Options", value: "SAMEORIGIN", state: "present" }
  - { name: "X-Powered-By", value: "ASP", state: "absent" }
  - { name: "X-Powered-By", value: "ASP.NET", state: "absent" }

iis_custom_headers_restart_iis: True

示例剧本

任务依赖于使用 Powershell 的 web 服务器 (IIS) 管理 cmdlets Add-WebConfigurationPropertyRemove-WebConfigurationProperty

- hosts: iis_servers
  roles:
     - role: deekayen.iis_custom_headers
       iis_custom_headers:
         - { name: "Strict-Transport-Security", value: "max-age=31536000", status: "present" }
         - { name: "X-Frame-Options", value: "SAMEORIGIN", status: "present" }
         - { name: "X-Powered-By", value: "ASP.NET", status: "absent" }

结果将向全局 XML 配置添加 customHeaders 元素:

<configuration>
   <system.webServer>
      <httpProtocol>
         <customHeaders>
            <add name="Strict-Transport-Security" value="max-age=31536000" />
            <add name="X-Frame-Options" value="SAMEORIGIN" />
         </customHeaders>
      </httpProtocol>
   </system.webServer>
</configuration>

要求

  • IIS

依赖

无。

许可证

BSD

关于项目

Add or remove global, custom headers from IIS web sites on Microsoft Windows.

安装
ansible-galaxy install deekayen.iis_custom_headers
许可证
bsd-3-clause
下载
1k
拥有者
My initials spelled as a word - pronounced /dEE-kAY-En/