使用iis反向代理
先下载 application-request-routing iis反向代理工具,https://www.iis.net/downloads/microsoft/application-request-routing 点击下载
安装后启用代理:
启用代理后,到要代理的站点下修改添加配置项
比如我们前后端分开部署:
前端访问地址:http://localhost:8080
后端访问地址:http://localhost:8081/api....
要想访问http://localhost:8080/api....重写到http://localhost:8081/api....
则在http://localhost:8080的web.config中配置以下内容
<rewrite> <rules> <rule name="API Rule" enabled="true" stopProcessing="true"> <match url="(api)(/.*)|(xls)(/.*)|(temp)(/.*)|(upload)(/.*)" /> <action type="Rewrite" url="http://localhost:8081/{R:0}" /> </rule> <rule name="Angular Rule" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="/" /> </rule> </rules> </rewrite>
也可以在iis 站点 的 url 重写模块配置