我有一个 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
URL 重写如下所示
<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 重写或访问其他服务器的限制?
最佳答案
重写外部 URL 称为反向代理。此功能是通过 ARR + Url Rewrite 的组合来实现的。这是 IIS 的两个独立模块。
Azure 网站上默认不启用反向代理。但有一个技巧可以启用它。 IIS 团队(或前 IIS 团队)的 Ruslan Y. 在 how to enable reverse proxy on Azure Web Sites here 上撰写了一篇博客文章。
注意 - 我还没有亲自测试过这个技巧,所以不能说它是否仍然有效(自从 Ruslan 的博客以来,Azure 网站已经有了很大的发展,这个功能可能已被禁用),但仍然值得一试。
关于iis - Azure 网站上的 URL 重写到另一台服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27479469/