html - 带有 ssl 和 www 重定向的 Angular 通用 Web 配置文件
问题描述
我的 Angular 通用项目的 web.config 文件有点问题。我的 web.config 文件是这样的;
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="main.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我们正在尝试在链接中没有写入 www 时添加 www 重定向,并且在 url 中没有写入 https 时添加 https 重定向。但我们无法做到这一点。
我是否需要为此从 Angular 做一些事情?
我们如何将这两个重定向添加到我们的 Angular 通用 Web 配置中?
解决方案
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000"/>
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1; mode=block" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the main.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="main.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^main.js\/debug[\/]?" />
</rule>
<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<match url="^(?!.*login).*$"></match>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
</conditions>
<action type="Rewrite" url="main.js"/>
</rule>
</rules>
<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>
</rewrite>
<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />
<!-- Restart the server if any of these files change -->
<iisnode watchedFiles="web.config;*.js;browser/*.*" />
</system.webServer>
</configuration>
推荐阅读
- ios - iOS - 播放从音源加载的多个音符,具有特定的持续时间和可能停止个别
- regex - 在第一个前瞻匹配中停止,有两个选项
- ruby-on-rails - 类别中的名称错误#index
- c++ - 如何将 CMSampleBufferRef/CIImage/UIImage 转换为像素,例如 uint8_t[]
- swift - 泛型和约束(`Instance method '...' 要求 'T' 符合 'Decodable'`)
- debugging - 奇怪的问题。逐步完成工作,运行时没有
- php - 帮助在 eloquent 中查询关系
- android - 如何使用代码确定设备屏幕尺寸类别(小、正常、大)?
- javascript - 如何禁用链接的脚本?
- freemarker - Freemarker 在处理模板时将一个小的双精度(如 0.0001)更改为零