Warm tip: This article is reproduced from serverfault.com, please click

iis-如果关闭了端口80,是否可以从HTTP重定向到HTTPS

(iis - Can I Redirect to HTTPS from HTTP if port 80 is closed)

发布于 2020-12-01 19:22:24

我有一个托管在Windows Server上的React Web应用程序。

IIS我创建URL Rewrite规则。当我从我们的网络中查看网站时,重写规则起作用,并且它从HTTP重定向到HTTPS。

但是,由于当我尝试使用HTTP查看网站时,端口80是在公共端关闭的,因此它永远不会重定向,只会超时。我假设这是因为端口关闭后,它实际上从未触及过页面,因此重定向从未生效。

有没有办法让网站在该端口关闭的情况下重定向到HTTPS?

这是我的web.config文件的外观:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
        <httpRedirect enabled="false" destination="https://mywebsitehere.com" />
        <rewrite>
            <rules>
                <rule name="http to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://mywebsitehere.com/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
 </system.webServer>
</configuration>
Questioner
JImmy G
Viewed
11
samwu 2020-12-02 13:58:06

答案是否定的,为了使服务器中的任何形式的HTTP重定向都能正常工作,服务器必须能够在端口80上获得传入的连接HTTP请求,然后它将发送3xx响应以告知浏览器再次尝试一个不同的URL,该URL将是HTTPS URL。如果HTTP请求在服务器获取到请求之前已关闭,则自然无法执行任何操作。