解决Azure Web App 无法使用URL Rewrite,404 Not Found状态 (Enable Application Request Routing on Azure App Service)

简介azure web app 最近有个需要重写访问到其它环境,本以为是个简单的事情,结果有坑。记录下解决方案

azure web app 最近有个需要重写访问到其它环境,本以为是个简单的事情,结果有坑,一通查找,本以为要下定论web app就是不支持ARR的时候,看到了大佬的解决方案,在此记录下。

原文地址:https://edi.wang/post/2020/11/2/how-to-enable-application-request-routing-on-azure-app-service

在Azure Web App Azure Service上开始ARR服务。
这个没有可视化配置的地方,也造成了很多时候,浪费很多时间查找解决访问。
QQ浏览器截图20210723150241.png

  1. 在需要开启ARR的Web App Azure portal上找到 【高级工具】, 点击【转到】
  2. 在顶层菜单栏【Debug Console】下找到【PowerShell】
  3. 打开【site】文件夹,查找【applicationHost.xdt】文件
  4. 如果存在该文件,点击编辑,如果不存在,点击添加文件
  5. 在文件中添加下面内容
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <system.webServer> <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" /> </system.webServer> </configuration>
  1. 重启Web App

附加一个 Rewrite 规则,目的是把所有请求代理到指定的域,状态是200。适用于SignalR 和 WebSocket

<rewrite> <rules> <rule name="rewrite" stopProcessing="true"> <match url="^(.*)" /> <conditions> <add input="{CACHE_URL}" pattern="(.*)://" /> </conditions> <action type="Rewrite" url="{C:1}://[你的域名]/{R:1}" logRewrittenUrl="true" /> </rule> </rules> </rewrite>

本站发布的文章受知识共享协议保护,转载、收录请标明出处。

评论


昵称:   邮箱:

Top
An error has occurred. This application may no longer respond until reloaded.Reload 🗙