2017-08-28 91 views
0

我最近使用AWS Elastic Beanstalk创建了一个Web应用程序,并设置了一个EC2经典负载平衡器来将HTTP URL重定向到HTTPS。目前,我可以通过HTTP或HTTPS访问我的网站,但我想要将其自动发送到HTTPS的任何请求。我使用AWS Toolkit从Visual Studio 2015开发并部署了我的ASP.NET MVC应用程序(否则,所有网站功能都已在AWS上设置)。我对AWS非常陌生,在仔细查看了许多关于此的帖子之后,一直无法找到强制将HTTP从HTTP重定向到HTTPS的方法。我看着这个网站https://oanhnn.github.io/2016-02-29/how-to-force-https-behind-aws-elb.html,但不知道如何实施讨论的内容。如果有人知道如何做到这一点,或知道有关这方面的优秀文档,我将不胜感激。ASP.NET MVC应用程序 - AWS负载平衡器重定向Http到https

回答

1

你需要:

  1. 你的Windows服务器上安装URL Rewrite
  2. 添加以下<rewrite>部分Web.config文件:

的Web.config


<configuration> 

    ... 

    <system.webServer> 

    ... 

    <rewrite> 
     <rules> 
     <rule name="Redirect to HTTPS" stopProcessing="true"> 
      <match url="(.*)" /> 
      <conditions> 
      <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
     </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> 
    </system.webServer> 
</configuration> 
+0

谢谢!修复了这个问题 – EvanL

相关问题