Ros*_*ace 26 asp.net iis url-rewriting amazon-web-services amazon-elastic-beanstalk
当你在弹性beanstalk负载均衡器后面时,如何使用IIS的url重写模块强制用户使用ssl?
Ros*_*ace 40
由于一些原因,这比听起来更难.一,负载均衡器正在处理ssl,因此从负载均衡器传递的请求永远不会使用ssl.如果使用传统的重写规则,您将获得无限循环的重定向.另一个需要解决的问题是,如果AWS健康检查收到重定向响应,它将失败.
在web.config的<system.webServer><rewrite><rules>部分中添加下面的重写规则:
<rule name="Force Https" stopProcessing="true">
<match url="healthcheck.html" negate="true" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)请注意,规则匹配除了我们的healthcheck文件之外的任何内容.这可以确保负载均衡器的运行状况检查成功,并且不会错误地将服务器从负载中丢弃.
负载均衡器在标头中传递X-Forwarded-Proto值,让我们知道请求是否通过https.如果该值不是https,则触发我们的规则,并使用https返回永久重定向.
Luk*_*uke 13
首先,我要感谢Ross的原始答案,它让我开始构建一个IIS URL重写规则,该规则通过使用我在网站支持AWS Elastic Load之前使用的现有HTTP到HTTPS重定向规则为我工作平衡器.
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" />
<add input="{REMOTE_HOST}" pattern="localhost" negate="true" />
<add input="{REMOTE_ADDR}" pattern="127.0.0.1" negate="true" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
此规则允许您在Visual Studio中或在端口80上的服务器上本地访问您的站点,而无需通过HTTPS访问,因此您只需要在服务器上具有端口80的绑定.它没有遭受别人提到的事情(重复的查询等).
我个人对健康检查没有任何问题,我不需要在服务器上创建一个弹性负载均衡器来ping的文件.我将负载均衡器设置为运行状况检查TCP:80并且可以正常运行.
| 归档时间: |
|
| 查看次数: |
13684 次 |
| 最近记录: |