2014-04-28 47 views
8

我有一個自託管的API在端口8080上運行。在端口80上是我的網站服務器(IIS 7.5),我的網站無法訪問。我添加了一個應用程序「MyApiTestsite」。現在,所有的請求/ API /或/ signalr /我想轉發到端口8080:IIS:URL Rewrite/signalr /和/ api /到端口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> 

我查了日誌文件和規則將匹配。然而,這並不在所有的工作:

  • 我不知道如何擺脫RelativePath(我的應用程序)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 PO試了一下ST。但是,它仍然不起作用。該網址似乎不錯,但在MvcHandler接管並返回404:

URL_REWRITE_END RequestURL = 「HTTP:// myCompany中:8080/signalr /集線器」

USER_SET =進行AuthType 「」,用戶名= 「」 ,SupportsIsInRole = 「真」

HANDLER_CHANGED
OldHandlerName = 「ExtensionlessUrlHandler集成-4.0」, NewHandlerName = 「System.Web.Mvc.MvcHandler」, NewHandlerModules = 「ManagedPipelineHandler」, NewHandlerScriptProcessor = 「」, NewHan dlerType = 「System.Web.Mvc.MvcHandler,System.Web.Mvc, 版本= 5.1.0.0」

GENERAL_SEND_CUSTOM_ERROR的HTTPStatus = 「404」,HttpSubStatus = 「4」, FileNameOrURL = 「404.htm」

更新2:

這裏是我想要做一個圖片...

enter image description here

更新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" 
+1

是correcyly配置你的IIS?請參閱http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/supported-platforms以獲取確切說明 –

+0

讓我們這樣說:如果我硬編碼API/SignalR訪問在端口8080上並使用CORS,然後一切按預期工作。但是,我想隱藏用戶的這些信息。 – Dunken

+0

ARR不應該是必需的,只是URL重寫。 –

回答

0

配置以下URL重寫規則:

Requested URL: Matches the pattern 
Using: Regular Expressions 
Pattern: MyApiTestsite/(signalr/.*) 
Action: Rewrite 
Rewrite URL: http://mycompany:8080/{R:1} 

編輯:{R:1}捕獲的第一個匹配,因爲它應該是,但隨後得到了改回舊的URL我的URL得到了改變正則表達式組在這種情況下匹配(signalr/.*)。如果是{R:0},它會放入匹配的整個相對URL。 有關更多信息,請參閱IIS URL Rewrite {R:N} clarification

+0

謝謝。但是,我認爲我的規則在應用時並不是錯誤的。問題是爲什麼它會變回... – Dunken

+0

從技術上說,你的規則沒有錯,但它沒有做你想做的事 - 例如,從URL中刪除MyApiTestsite。我建議給你的規則應該這樣做。 –

+0

另外我的建議是關於使用簡單的URL重寫。我不認爲你需要服務器農場來進行你想要的設置。 –

0

試試這個:This Works!

<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然後 enter image description here