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

时间:2018-08-20 09:29:46

标签: rest url-rewriting reverse-proxy iis-10 tomcat9

基本上,我想使用反向代理重写url: 来自:

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

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

我已经在Tomcat中的C:\ Tomcat \ apache-tomcat-9.0.7 \ webapps \ eacc下部署了Spring Boot Rest Full 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文件。

当我尝试打一个像 www.xyz.in/eacc/api/fetchVendors 这样的帖子时,收到HTTP 404服务器错误。

描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除,名称更改或暂时不可用。请查看以下网址,并确保其拼写正确。

请求的网址:/ eacc / api / fetchVendors

我的 / eacc-虚拟目录

的web.config文件
<?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 个答案:

答案 0 :(得分:1)

对我来说,这适用于IIS:

转到IIS根节点>> ARR

enter image description here

点击“服务器代理设置”选项

enter image description here

并启用它:

enter image description here

答案 1 :(得分:0)

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