在azure中将HTTP重定向到HTTPS(带负载均衡器) [英] Redirect HTTP to HTTPS in azure (with load balancer)

查看:202
本文介绍了在azure中将HTTP重定向到HTTPS(带负载均衡器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Azure中有两个负载均衡的Web服务器。

我们刚刚在这些azure网站上安装了SSL,将其转换为HTTPS。



现在我们希望任何以HTTP形式进入的请求都应该更改/重定向到HTTPS连接。



所以,我测试我在我的本地机器上创建了一个已发布的网站,然后添加了自签名的

SSL证书以获得一个安全的网站。然后我使用URL重写将我的HTTP站点指向HTTPS。

我在Web.config中使用它。



这对我来说很完美当地出版的网站。



但这在Azure服务器上失败并且给我一个内部服务器错误。



有什么想法吗?



我在Web.config中使用以下内容进行URL重写



We have 2 Web servers in Azure that are Load balanced.
We just installed SSL in our these azure websites to convert it to HTTPS.

Now we want that any request coming in as HTTP should be changed/redirected to HTTPS connection.

So, I for testing I created a published website on my local machine, then added self signed
SSL certificate to get a secure site. Then I used URL rewrite to direct my HTTP site to HTTPS.
I used this in Web.config.

This works perfectly on my local published site.

But this fails on the Azure server and gives me an Internal Server Error.

Any ideas?

I used the following in Web.config for the URL rewrite

<rewrite>
    <rules>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
            <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="Off" />
                    <add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="SeeOther" />
        </rule>
    </rules>
</rewrite>





我有什么试过:



在Web.Config中尝试重写URL。

它在Azure服务器上不起作用。



What I have tried:

Tried URL Rewrite in Web.Config .
It did not work on Azure Server.

推荐答案

| ^ head


/ >
< / conditions >
< action type = 重定向 url = https:// {HTTP_HOST} {REQUEST_URI} redirectType = SeeOther / >
< / rule >
< / rules >
< / rewrite >
" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="SeeOther" /> </rule> </rules> </rewrite>





我的尝试:



在Web.Config中尝试重写URL。

它在Azure服务器上不起作用。



What I have tried:

Tried URL Rewrite in Web.Config .
It did not work on Azure Server.


我弄清楚了。

我在服务器上的IIS上缺少URL重写模块。安装完成了诀窍



https://www.iis.net/downloads/microsoft/url-rewrite





现在,IIS服务器可以将URL请求从HTTP重定向到HTTPS
I figured it out.
I was missing the URL rewrite module on IIS on the server. Installing that did the trick

https://www.iis.net/downloads/microsoft/url-rewrite


Now the IIS server can redirect the url requests from HTTP to HTTPS


这篇关于在azure中将HTTP重定向到HTTPS(带负载均衡器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆