【问题标题】:Can I Redirect to HTTPS from HTTP if port 80 is closed如果端口 80 关闭,我可以从 HTTP 重定向到 HTTPS
【发布时间】:2021-03-13 18:22:05
【问题描述】:

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

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

但是,由于端口 80 在公共端关闭,当我尝试在 HTTP 中查看网站时,它永远不会重定向并且只是超时。我假设这是因为自从端口关闭以来它从未真正点击过页面,因此重定向永远不会启动。

有没有办法让网站在该端口关闭的情况下仍重定向到 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>

【问题讨论】:

  • 不可能...只有通过防火墙配置才有可能。

标签: redirect iis https url-rewriting web-config


【解决方案1】:

答案是否定的,为了让任何形式的 HTTP 重定向在服务器中起作用,服务器必须能够在端口 80 上获取传入的连接 HTTP 请求,然后它会发送一个 3xx 响应告诉浏览器使用不同的 URL 重试,该 URL 将是 HTTPS URL。如果 HTTP 请求在服务器获取到之前就关闭了,自然也就无能为力了。

【讨论】:

    猜你喜欢
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    相关资源
    最近更新 更多