使用 IIS 作为动态转发的反向代理

问题描述 投票:0回答:1

下午好,

我需要一个反向代理解决方案来将 API 调用从服务器转发到不同的客户端。为此,我想使用带有 ARR 的 IIS。目标客户端的地址包含在服务器的 HTTP 调用中:

http://Proxyserver/Targetcomputer/API_String

我想将 URL 重写为:http://Targetcomputer/API_String

我已经使用以下模式设置了 URL 重写规则:

`^(.*)/(.*)`

这会导致以下结果:

`{R:0} Targetcomputer/API_String`
`{R:1} Targetcomputer`
`{R:2} API_String`

我使用以下表达方式进行释义:

`http://{R:1}/{R:2}`

但是,在我看来,动态重定向到

{R:1}
是不可能的。 聪明人有什么建议吗?

提前谢谢您!

安德烈亚斯

创建各种转发规则没有成功 Web服务器似乎只能访问本地资源。

以下是 web.config 中的重写规则:

<rule name="Test" enabled="true" stopProcessing="true">
      <match url="^([^/]+)/([^/]+)" />
      <action type="Rewrite" url="http://{R:1}/{R:2}" LogRewrittenUrl="true" />
</rule>

更多信息,以下是失败请求日志中的详细信息:

<failedRequest url="http://localhost:80/www.ibm.com"
               siteId="1"
               appPoolId="DefaultAppPool"
               processId="9580"
               verb="GET"
               remoteUserName=""
               userName=""
               tokenUserName="NT-AUTORITÄT\IUSR"
               authenticationType="anonymous"
               activityId="{4000011E-0000-F000-B63F-84710C7967BB}"
               failureReason="STATUS_CODE"
               statusCode="404"
               triggerStatusCode="404"
               timeTaken="47"
               xmlns:freb="http://schemas.microsoft.com/win/2006/06/iis/freb"
               >

URL_REWRITE 部分:

<Opcode>URL_REWRITE_START</Opcode>
  <Keywords>
   <Keyword>Rewrite</Keyword>
  </Keywords>
  <freb:Description Data="Scope">Global</freb:Description>
  <freb:Description Data="Type">Inbound</freb:Description>
 </RenderingInfo>
 <ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
  <EventGuid>{0469ABFA-1BB2-466A-B645-E3E15A02F38B}</EventGuid>
 </ExtendedTracingInfo>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
  <Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
  <EventID>0</EventID>
  <Version>1</Version>
  <Level>5</Level>
  <Opcode>3</Opcode>
  <Keywords>0x400</Keywords>
  <TimeCreated SystemTime="2024-09-12T07:37:35.518Z"/>
  <Correlation ActivityID="{4000011E-0000-F000-B63F-84710C7967BB}"/>
  <Execution ProcessID="9580" ThreadID="1488"/>
  <Computer>1BLUE</Computer>
 </System>
 <EventData>
  <Data Name="ContextId">{4000011E-0000-F000-B63F-84710C7967BB}</Data>
  <Data Name="RuleName">Forwarding</Data>
  <Data Name="RequestURL">www.ibm.com</Data>
  <Data Name="QueryString"></Data>
  <Data Name="PatternSyntax">0</Data>
  <Data Name="StopProcessing">true</Data>
  <Data Name="RelativePath">/</Data>
 </EventData>
 <RenderingInfo Culture="de-DE">
  <Opcode>RULE_EVALUATION_START</Opcode>
  <Keywords>
   <Keyword>Rewrite</Keyword>
  </Keywords>
  <freb:Description Data="PatternSyntax">Regex</freb:Description>
 </RenderingInfo>
 <ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
  <EventGuid>{0469ABFA-1BB2-466A-B645-E3E15A02F38B}</EventGuid>
 </ExtendedTracingInfo>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
  <Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
  <EventID>0</EventID>
  <Version>1</Version>
  <Level>5</Level>
  <Opcode>10</Opcode>
  <Keywords>0x400</Keywords>
  <TimeCreated SystemTime="2024-09-12T07:37:35.518Z"/>
  <Correlation ActivityID="{4000011E-0000-F000-B63F-84710C7967BB}"/>
  <Execution ProcessID="9580" ThreadID="1488"/>
  <Computer>1BLUE</Computer>
 </System>
 <EventData>
  <Data Name="ContextId">{4000011E-0000-F000-B63F-84710C7967BB}</Data>
  <Data Name="Pattern">^(.*)/(.*)</Data>
  <Data Name="Input">www.ibm.com</Data>
  <Data Name="Negate">false</Data>
  <Data Name="Matched">false</Data>
 </EventData>
 <RenderingInfo Culture="de-DE">
  <Opcode>PATTERN_MATCH</Opcode>
  <Keywords>
   <Keyword>Rewrite</Keyword>
  </Keywords>
 </RenderingInfo>
 <ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
  <EventGuid>{0469ABFA-1BB2-466A-B645-E3E15A02F38B}</EventGuid>
 </ExtendedTracingInfo>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
  <Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
  <EventID>0</EventID>
  <Version>1</Version>
  <Level>5</Level>
  <Opcode>4</Opcode>
  <Keywords>0x400</Keywords>
  <TimeCreated SystemTime="2024-09-12T07:37:35.518Z"/>
  <Correlation ActivityID="{4000011E-0000-F000-B63F-84710C7967BB}"/>
  <Execution ProcessID="9580" ThreadID="1488"/>
  <Computer>1BLUE</Computer>
 </System>
 <EventData>
  <Data Name="ContextId">{4000011E-0000-F000-B63F-84710C7967BB}</Data>
  <Data Name="RuleName">Forwarding</Data>
  <Data Name="RequestURL">www.ibm.com</Data>
  <Data Name="QueryString"></Data>
  <Data Name="StopProcessing">true</Data>
  <Data Name="Succeeded">false</Data>
 </EventData>
 <RenderingInfo Culture="de-DE">
  <Opcode>RULE_EVALUATION_END</Opcode>
  <Keywords>
   <Keyword>Rewrite</Keyword>
  </Keywords>
 </RenderingInfo>
 <ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
  <EventGuid>{0469ABFA-1BB2-466A-B645-E3E15A02F38B}</EventGuid>
 </ExtendedTracingInfo>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
  <Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
  <EventID>0</EventID>
  <Version>1</Version>
  <Level>4</Level>
  <Opcode>2</Opcode>
  <Keywords>0x400</Keywords>
  <TimeCreated SystemTime="2024-09-12T07:37:35.518Z"/>
  <Correlation ActivityID="{4000011E-0000-F000-B63F-84710C7967BB}"/>
  <Execution ProcessID="9580" ThreadID="1488"/>
  <Computer>1BLUE</Computer>
 </System>
 <EventData>
  <Data Name="ContextId">{4000011E-0000-F000-B63F-84710C7967BB}</Data>
  <Data Name="RequestURL"></Data>
 </EventData>
 <RenderingInfo Culture="de-DE">
  <Opcode>URL_REWRITE_END</Opcode>
iis reverse-proxy
1个回答
0
投票

尝试在您的

web.config
中使用下面的重写规则。

    <rule name="Test" enabled="true" stopProcessing="true">
  <match url="^[^/]+/([^/]+)/(.*)" />
  <action type="Rewrite" url="http://{R:1}/{R:2}" LogRewrittenUrl="true" />
</rule>

{R:1} 将捕获 Targetcomputer,{R:2} 将捕获 API_String

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.