解决方法
由于一些原因,这比听起来更困难。一,负载均衡器负责ssl,因此从负载均衡器传递的请求永远不会使用ssl。如果使用传统的重写规则,您将获得无限循环的重定向。另一个需要解决的问题是,如果AWS健康检查收到重定向响应,它将失败。
>解决方案的第一步是创建healthcheck.html页面并将其设置在根目录中。内容是什么并不重要。
>设置负载均衡器以使用healthcheck.html文件进行运行状况检查。
>在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>
请注意,规则匹配除了我们的healthcheck文件之外的任何内容。这可以确保负载均衡器的运行状况检查成功,并且不会错误地从负载中丢弃我们的服务器。
负载均衡器在标头中传递X-Forwarded-Proto值,让我们知道请求是否通过https。如果该值不是https,则触发我们的规则,并使用https返回永久重定向。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。