2017-08-28 85 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

相關問題