英文:
How to configure IIS 10 to forward requests to web apps
问题
I want IIS 10 to redirect requests to several other web apps (ASP.NET Core 6.0 and Angular 14) <br/>
我想让 IIS 10 将请求重定向到几个其他Web应用程序(ASP.NET Core 6.0 和 Angular 14) <br/>
Let's say I have Kestrel listening on http://localhost:5009/ serving one of those apps, I want to type
假设我有Kestrel监听 http://localhost:5009/ 为其中一个应用提供服务,我想要输入
http://localhost/PassThrough/
into browser address and to have it redirected to
浏览器地址中输入并要求将其重定向到
http://localhost:5171/
And also
还有
http://localhost/PassThrough/todo/param1
to
http://localhost:5171/todo/param1
UPDATE:
Tried a rewrite URL method suggested by @TengFeiXie
更新:
尝试了@TengFeiXie建议的重写URL方法
and a bunch of variants. None of it worked.
以及其他几种变体。都没有奏效。
The problem with this method I think is IIS will only allow you to match a pattern after the first / and if you rewrite the matched part it will not add port in the correct place (before the first /).
我认为这种方法的问题在于IIS只允许您在第一个/之后匹配模式,如果您重写匹配的部分,它不会在正确的位置(在第一个/之前)添加端口。
Redirect will also not redirect correctly for the same reason.
由于相同的原因,重定向也不会正确重定向。
The second suggestion - reverse proxy also did not bare fruit:
第二个建议 - 反向代理也没有取得成果:
Both
两者
<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>
and
以及
<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>
in web.config
在web.config中
end up redirecting to
最终重定向到
http://localhost/localhost:5171
instead of
而不是
http://localhost:5171
So same issue basically in both suggestions. It boils down to setting up the rule. If you are able to provide the rule that works let's say in xml form I'd be happy to test it.
基本上两种建议都有相同的问题。问题归结为设置规则。如果您能提供有效的规则,比如以XML形式,我会很愿意测试它。
<br/>
Latest:
最新的:
<?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>
英文:
I want IIS 10 to redirect requests to several other web apps (ASP.NET Core 6.0 and Angular 14) <br/>
Let's say I have Kestrel listening on http://localhost:5009/ serving one of those apps, I want to type
http://localhost/PassThrough/
into browser address and to have it redirected to
http://localhost:5171/
And also
http://localhost/PassThrough/todo/param1
to
http://localhost:5171/todo/param1
UPDATE:
Tried a rewrite URL method suggested by @TengFeiXie
and a bunch of variants. None of it worked.
The problem with this method I think is IIS will only allow you to match a pattern after the first / and if you rewrite the matched part it will not add port in the correct place (before the first /).
Redirect will also not redirect correctly for the same reason.
The second suggestion - reverse proxy also did not bare fruit:
Both
<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>
and
<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>
in web.config
end up redirecting to
http://localhost/localhost:5171
instead of
http://localhost:5171
So same issue basically in both suggestions. It boils down to setting up the rule. If you are able to provide the rule that works let's say in xml form I'd be happy to test it.
<br/>
Latest:
<?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>
答案1
得分: 1
IIS提供官方组件,URL重定向或反向代理都可以满足您的需求。
-
获取URL重写模块:
https://iis-umbraco.azurewebsites.net/downloads/microsoft/url-rewrite。
您可以参考官方文档中的步骤来创建重定向规则,将http://localhost/App1/重定向到http://localhost:5009/。 -
反向代理需要应用程序请求路由:
https://iis-umbraco.azurewebsites.net/downloads/microsoft/application-request-routing。
URL重定向和反向代理的官方文档具有详细的步骤和参考示例。
更新:
好的,看来您对重写规则不太熟悉。我将演示从**http://localhost/PassThrough/到http://localhost:5171/**的步骤。您会发现这非常容易。
我在端口5174上有一个article.html。
然后我在Default Web Site(端口80)中添加了以下入站规则。
在Web.config中
<rules>
<rule name="ReverseProxy" stopProcessing="true">
<match url="passthrough/(.*)" />
<action type="Rewrite" url="http://localhost:5171/{R:1}" />
</rule>
</rules>
请求:http://localhost/PassThrough/article.html。成功获取article.html。
英文:
IIS provides official components, URL Redirection or Reverse Proxy both can meet your needs.
-
Get the URL Rewrite module:
https://iis-umbraco.azurewebsites.net/downloads/microsoft/url-rewrite.
You can refer to the steps in the official documentation to
create redirect rules, redirect from http://localhost/App1/ to
http://localhost:5009/. -
Reverse Proxy needs Application Request Routing:
https://iis-umbraco.azurewebsites.net/downloads/microsoft/application-request-routing.Configuring Rules for the Reverse Proxy:
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing#configuring-rules-for-the-reverse-proxy.
The official documentation for URL redirection and reverse proxy has detailed steps and reference examples.
Update:
OK, It seems you are not familiar with rewrite rules. I'll demonstrate the steps to go from http://localhost/PassThrough/ to http://localhost:5171/. You'll find it's really easy.
I have an article.html on port 5174.
Then I added the following inbound rules in Default Web Site(port 80).
In Web.config
<rules>
<rule name="ReverseProxy" stopProcessing="true">
<match url="passthrough/(.*)" />
<action type="Rewrite" url="http://localhost:5171/{R:1}" />
</rule>
</rules>
Request: http://localhost/PassThrough/article.html. Successfully got the article.html.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论