在Azure网站上将URL重写到另一台服务器

时间:2014-12-15 07:46:59

标签: iis azure ember.js url-rewriting

我有一个Ember应用程序,它使用CORS访问不同子域上的API。 由于IE8和IE9没有完整的CORS支持,我需要创建一个代理来访问API。

Ember应用程序部署在Azure网站上,API是Web角色。我曾尝试使用URL重写创建代理,但我只获得404 Not Found。

我想要以下行为

https://www.cloudstorez.com/rewrite/cms/public/designs

重写

https://cms-public.cloudstorez.com/designs

网址重写如下所示

<rule name="Rewrite to APIs" stopProcessing="true">
    <match url="^rewrite/([^/]*)/([^/]*)/(.*)" />
    <action type="Rewrite" url="https://{R:1}-{R:2}.cloudstorez.com/{R:3}" />
</rule>

如果我改为执行相应的重定向,则可以正常工作。

<rule name="Redirect to APIs" stopProcessing="true">
    <match url="^redirect/([^/]*)/([^/]*)/(.*)" />
    <action type="Redirect" url="https://{R:1}-{R:2}.cloudstorez.com/{R:3}" />
</rule>

我的重写是否有问题,或者Azure网站是否有关于URL重写或访问其他服务器的限制?

1 个答案:

答案 0 :(得分:4)

重写到外部URL称为反向代理。此功能是通过ARR + Url Rewrite的组合实现的。这是IIS的两个独立模块。

Azure网站上默认不启用反向代理。但是有一个技巧可以启用它。来自IIS团队(或前IIS团队)的Ruslan Y.撰写了一篇关于how to enable reverse proxy on Azure Web Sites here的博客文章。

注意 - 我没有亲自测试过这个技巧,所以不能说它是否仍然有效(自从Ruslan的博客以来,Azure网站已经有了很大的发展,并且这个功能可能已被禁用),但仍然值得一试。