在弹性 beantalk 的负载均衡器中通过 IIS 中的 url 重写重定向到 https

编程入门 行业动态 更新时间:2024-10-28 12:18:28
本文介绍了在弹性 beantalk 的负载均衡器中通过 IIS 中的 url 重写重定向到 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当您在弹性 beantalk 负载均衡器后面时,您如何使用 IIS 的 url 重写模块强制用户使用 ssl?

How do you use IIS's url rewrite module to force users to use ssl while you are behind an elastic beanstalk load balancer?

推荐答案

由于一些原因,这比听起来要困难得多.一,负载平衡器负责 ssl,因此从负载平衡器传递的请求永远不会使用 ssl.如果您使用传统的重写规则,您将获得无限循环的重定向.另一个需要解决的问题是,如果收到重定向响应,AWS 运行状况检查将失败.

This is more difficult than it sounds for a few reasons. One, the load balancer is taking care of ssl so requests passed from the load balancer are never using ssl. If you use the traditional rewrite rule you will get an infinite loop of redirects. Another issue to contend with is that the AWS healthcheck will fail if it receives a redirect response.

  • 解决方案的第一步是创建一个healthcheck.html页面并将其设置在根目录中.内容是什么并不重要.
  • 将您的负载均衡器设置为使用 healthcheck.html 文件进行健康检查.
  • 在 web.config 的 部分添加以下重写规则:

  • The first step in the solution is to create a healthcheck.html page and set it in the root directory. It doesn't matter what the content is.
  • Set your load balancer to use the healthcheck.html file for health checks.
  • Add the rewrite rule below in your web.config's <system.webServer><rewrite><rules> section: <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="{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" /> </rule>

  • 请注意,除了我们的健康检查文件之外,规则匹配的任何内容.这可以确保负载平衡器的健康检查成功,并且不会错误地将我们的服务器从负载中删除.

    Notice that the rule match is on anything but our healthcheck file. This makes sure the load balancer's health check will succeed and not mistakenly drop our server from the load.

    负载均衡器在标头中传递 X-Forwarded-Proto 值,它让我们知道请求是否通过 https.如果该值不是 https 并返回使用 https 的永久重定向,我们的规则就会触发.

    The load balancer passes the X-Forwarded-Proto value in the header which lets us know if the request was through https or not. Our rule triggers if that value is not https and returns a permanent redirect using https.

    更多推荐

    在弹性 beantalk 的负载均衡器中通过 IIS 中的 url 重写重定向到 https

    本文发布于:2023-11-23 23:45:01,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1623212.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:重写   弹性   重定向   器中   负载均衡

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!