反向代理不适用于 .svc url?

反向代理不适用于 .svc url?

这是我尝试使用 url 重写从IISmysubdomaintarget.mytargetdomain.com进行反向代理mysubdomainreal.myrealdomain.com

<configuration>
    <system.webServer>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket,Rewrite,RequestRouting" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="400-999" />
                </add>
            </traceFailedRequests>
        </tracing>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="https://mysubdomainreal.myrealdomain.com/{R:1}" />
                    <serverVariables>
                        <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                        <set name="HTTP_ACCEPT_ENCODING" value="" />
                    </serverVariables>
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://mysubdomainreal.myrealdomain.com/(.*)" />
                    <action type="Rewrite" value="http{R:1}://mysubdomainreal.myrealdomain.com/{R:2}" />
                </rule>
                <rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
                    <match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
                    <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                    <preCondition name="NeedsRestoringAcceptEncoding">
                        <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

如果我使用它来调用网站,mysubdomaintarget.mytargetdomain.com/myApp它会正常工作(呈现页面等)。但如果我调用,mysubdomaintarget.mytargetdomain.com/myApp.svc则会得到 404。

为什么?我的配置哪里错了?

编辑 这是 failedRequest 标签的属性:

<failedRequest url="http://mysubdomaintarget.mytargetdomain.com/myApp.svc"
               siteId="6"
               appPoolId="services"
               processId="2192"
               verb="GET"
               remoteUserName=""
               userName=""
               tokenUserName="NT AUTHORITY\IUSR"
               authenticationType="anonymous"
               activityId="{8000002B-0000-9900-B63F-84710C7967BB}"
               failureReason="STATUS_CODE"
               statusCode="404"
               triggerStatusCode="404"
               timeTaken="141"
               xmlns:freb="http://schemas.microsoft.com/win/2006/06/iis/freb"
               >

编辑2

浏览器打开的xml:

在此处输入图片描述

答案1

此 StackOverflow 帖子早在 2013 年,就有人建议你可能需要将属性添加multipleSiteBindingsEnabled="true"<serviceHostingEnvironment>WCF (.svc) 服务的 web.config 标记中。否则,WCF 将拒绝你的 HTTP 请求,因为它认为它不应该处理该主机名和路径的请求。

也许可以尝试一下?

相关内容