IIS URL重写 - 反向代理 - 响应404错误

3

基本上,我想使用反向代理重写URL:

从:

http://www.xyz.in/eacc/api/fetchVendors

到:

http://localhost:8080/eacc/api/fetchVendors

我已经在C:\Tomcat\apache-tomcat-9.0.7\webapps\eacc下部署了我的Spring Boot RESTful Web服务应用程序。

它包含许多POST调用,如/eacc/api/fetchVendors、/eacc/api/users、/eacc/api/clients等。

现在我想通过IIS公开这个eacc REST应用程序。

我有一个名为www.xyz.in的主要网站。

在网站(www.xyz.in)下添加了虚拟目录/eacc。物理路径:C:\inetpub\wwwroot\eacc。下面是web.config文件。

当我尝试访问一个POST调用,例如www.xyz.in/eacc/api/fetchVendors时,会出现HTTP 404服务器错误。

描述:HTTP 404。您正在查找的资源(或其某个依赖项)可能已被删除、更改名称或暂时不可用。请检查以下URL,确保拼写正确。

请求的URL:/eacc/api/fetchVendors

我的web.config文件为/eacc - 虚拟目录

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="false" />
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:8080/eacc/{R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:8080/eacc/(.*)" />
                    <action type="Rewrite" value="http{R:1}://www.xyz.in/{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

我是一个新手,正在使用IIS Web服务器。我遇到了URL Rewrite反向代理模式的问题。我尝试了很多模式更改,但没有成功。希望得到任何人的帮助。

2个回答

10

对我而言,这在IIS上奏效:

前往IIS根节点 >> ARR

enter image description here

点击 "Server Proxy Settings" 选项

enter image description here

并启用它:

enter image description here


这对我很有效,我正在迁移到新服务器,只是复制了整个web.config,忘记启用此功能。 - Muhammad Ibnuh

1
Inbound Rule:
Use Patters : ^eacc.*
Rewrite URL : http://localhost:8080/{R:0}

Outbound Rule:
Pattern : localhost:8080
Value : www.xyz.com

另外,您需要添加代理设置(应用程序请求路由模块 - 服务器代理设置):

(tick) Enable Proxy
(untick) REverse Rewrite in response headers

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接