我有一个在端口8080上运行的自托管API。在端口80上是我的网络服务器(IIS 7.5),我的网站无法触及。我添加了一个应用程序“MyApiTestsite”。现在对/ api /或/ signalr / I的所有请求都要转发到端口8080:
http://mycompany/MyApiTestsite -> untouched
http://mycompany/MyApiTestsite/signalr/* -> http://mycompany:8080/signalr/*
http://mycompany/MyApiTestsite/api/* -> http://mycompany:8080/api/*
我已经安装了ARR
(这是否必要?)和URL Rewrite
。
这是我迄今为止的规则(对于SignalR):
<rule name="Rewrite SignalR to port 8080" patternSyntax="Wildcard" stopProcessing="true">
<match url="signalr/*" />
<serverVariables>
<set name="SERVER_PORT" value="8080" />
</serverVariables>
<action type="Rewrite" url="{R:0}" appendQueryString="true" logRewrittenUrl="false" />
</rule>
我检查了日志文件,规则得到匹配。但是,它根本不起作用:
MyApiTestsite
日志:
RULE_EVALUATION_END RuleName="Rewrite SignalR to port 8080", RequestURL="MyApiTestsite/signalr/hubs", QueryString="", StopProcessing="true", Succeeded="true"
URL_REWRITE_END RequestURL="/MyApiTestsite/signalr/hubs"
GENERAL_CHILD_REQUEST_START SiteId="4", RequestURL="http://mycompany:80/MyApiTestsite/signalr/hubs", RequestVerb="GET", RecursiveLevel="1"
更新 我现在根据this帖子尝试过。但是,它仍然无效。 URL看起来不错,但MvcHandler接管并返回404:
URL_REWRITE_END RequestURL =“http:// mycompany:8080 / signalsr / hubs”
USER_SET AuthType =“”,UserName =“”,SupportsIsInRole =“true”
HANDLER_CHANGED
OldHandlerName = “ExtensionlessUrlHandler集成-4.0”, NewHandlerName = “System.Web.Mvc.MvcHandler”, NewHandlerModules = “ManagedPipelineHandler”, NewHandlerScriptProcessor = “”, NewHandlerType =“System.Web.Mvc.MvcHandler,System.Web.Mvc, 版本= 5.1.0.0"GENERAL_SEND_CUSTOM_ERROR HttpStatus =“404”,HttpSubStatus =“4”, FileNameOrURL = “404.htm”
更新2:
这是我想要做的图片......
更新3
这次我尝试使用Server Farms
代替。我的网址已经改变了,但后来又改回了原来的网址:
ARR_WEBFARM_ROUTED WebFarm="mycompany API", Algorithm="LeastRequests"
HANDLER_CHANGED OldHandlerName="", NewHandlerName="ApplicationRequestRoutingHandler", NewHandlerModules="ApplicationRequestRouting", NewHandlerScriptProcessor="", NewHandlerType=""
ARR_SERVER_ROUTED RoutingReason="LoadBalancing", Server="mycompany", State="Active", TotalRequests="1", FailedRequests="0", CurrentRequests="1", BytesSent="0", BytesReceived="0", ResponseTime="0"
GENERAL_SET_REQUEST_HEADER HeaderName="Max-Forwards", HeaderValue="10", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-Forwarded-For", HeaderValue="xxx.xx.xx.xxx:52327", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-ARR-SSL", HeaderValue="", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-ARR-ClientCert", HeaderValue="", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="X-ARR-LOG-ID", HeaderValue="f8exxxc2-7a6d-4cf6-a3c6-ecde245a0d80", Replace="true"
GENERAL_SET_REQUEST_HEADER HeaderName="Connection", HeaderValue="", Replace="true"
//>>>>>now it gets changed back!!! Why????<<<<<<
URL_CHANGED OldUrl="http://mycompany API/signalr/hubs", NewUrl="/MyApiTestsite/signalr/hubs"
答案 0 :(得分:0)
配置以下网址重写规则:
Requested URL: Matches the pattern
Using: Regular Expressions
Pattern: MyApiTestsite/(signalr/.*)
Action: Rewrite
Rewrite URL: http://mycompany:8080/{R:1}
编辑:{R:1}
匹配第一个捕获的正则表达式组,在这种情况下匹配(signalr/.*)
。如果它是{R:0}
,它将放置匹配的整个相对URL。
有关详细信息,请参阅IIS URL Rewrite {R:N} clarification。
答案 1 :(得分:0)
试试这个:这个有效!
<rewrite>
<rewriteMaps>
<rewriteMap name="root">
<add key="/root/" value="/" />
</rewriteMap>
</rewriteMaps>
<rules>
<clear />
<rule name="MyRedirect" stopProcessing="true">
<match url="^MYApiTestsite/(api|signalr)(/.*)?" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="http://mycompany:8080/{R:1}{R:2}" />
</rule>
</rules>
</rewrite>
如果你想使用GUI那么