IIS 10配置请求转发至多Web应用的问题求助
IIS 10配置请求转发至多Web应用的问题求助
各位大佬,我现在碰到了个IIS配置的难题,想请大家帮忙看看!我想要让IIS 10把请求转发到多个不同的Web应用(包括ASP.NET Core 6.0和Angular 14项目)。
举个具体的场景:我有个Kestrel服务在http://localhost:5009/跑着其中一个应用,但我希望在浏览器地址栏输入http://localhost/PassThrough/时,能直接转发到http://localhost:5171/;同时输入http://localhost/PassThrough/todo/param1时,能转发到http://localhost:5171/todo/param1,路径参数也能完整保留。
已尝试的方案及问题
我试过@TengFeiXie建议的URL重写方法,还折腾了各种变体,但全都没生效。我琢磨着问题可能出在IIS的匹配逻辑上——它好像只能匹配第一个/之后的内容,重写的时候没法把端口号放在正确的位置(也就是第一个/之前),用重定向功能也遇到了同样的问题。
后来我又尝试了反向代理的配置,在web.config里写了两种规则,但结果都不尽人意:
第一种配置:
<rewrite> <rules> <rule name="Reverse Proxy to webmail" stopProcessing="true"> <match url="^PassThrough/(.*)" /> <action type="Rewrite" url="http://localhost:5171/{R:1}" /> </rule> </rules> </rewrite>
第二种配置:
<rewrite> <rules> <rule name="Reverse Proxy to webmail" stopProcessing="true"> <match url="http://localhost/PassThrough/(.*)" /> <action type="Rewrite" url="http://localhost:5171/{R:1}" /> </rule> </rules> </rewrite>
这两种配置最终都把请求重定向到了http://localhost/localhost:5171,完全不是我想要的http://localhost:5171,看来核心还是规则没写对。如果哪位大佬能提供可用的XML格式规则,我马上就去测试!
最新尝试的配置
这是我最新写的web.config配置,还是没解决问题:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="PassThrough" stopProcessing="true"> <match url="http://localhost/PassThrough(/(.*))*" /> <action type="Redirect" url="http://localhost:5171{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
备注:内容来源于stack exchange,提问作者ILIA BROUDNO
相关产品推荐
相关产品推荐

