Vue IIS部署 api 访问当前站点 代理跳转真实API 问题
先确认 ARR 装没装
IIS 管理器 → 点最上面的服务器名 → 右边功能视图找 "Application Request Routing Cache" 没有找到就是没有装
装步骤
方法一:用 Web Platform Installer(推荐)
- 在前端服务器上打开 IIS 管理器
- 点最上面的服务器名 → 右边找 "Web Platform Installer"(如果没有,去微软官网下载安装)
- 搜索
Application Request Routing - 安装 ARR 3.0(会自动带上依赖)
方法二:直接下载 MSI
- 下载地址:https://www.iis.net/downloads/microsoft/application-request-routing
- 选
WebPI链接或直接下ARRv3_setup.exe - 安装时一路下一步
打开 IIS 管理器 → 服务器节点 → Application Request Routing Cache → 右边 Server Proxy Settings → 勾选 Enable proxy → 点应用。
要重启IIS 重新打开IIS
vue web 站点web.config 调整
bash
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule4" stopProcessing="true">
<match url="^blog/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://192.168.74.4:8088/{R:1}" />
</rule>
<rule name="ReverseProxyInboundRule5" stopProcessing="true">
<match url="^moodle/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="https://xxxx/{R:1}" />
</rule>
<rule name="ReverseProxyInboundRule3" stopProcessing="true">
<match url="^api/(.*)" />
<action type="Rewrite" url="http://192.168.74.92:7108/api/{R:1}" />
</rule>
<rule name="API Rule" stopProcessing="true">
<match url="^(js|css)(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="Handle History Mode and custom 404/500" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
<rule name="SignalR" stopProcessing="true">
<match url="^teacherHub/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://localhost:7008/teacherHub" />
</rule>
</rules>
</rewrite>
<staticContent>
<remove fileExtension=".pdf" />
<mimeMap fileExtension=".pdf" mimeType="application/pdf" />
<mimeMap fileExtension=".properties" mimeType="text/plain" />
<mimeMap fileExtension=".bcmap" mimeType="octet-stream/bcmap" />
</staticContent>
<directoryBrowse enabled="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Expose-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>