IIS反向代理到不同的服务器 [英] IIS Reverse Proxy to Different Server

查看:518
本文介绍了IIS反向代理到不同的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出是否有可能在IIS中执行反向代理,实际上是在不同的Web服务器端点。我用它在同一台机器上遍历端口,但从不使用其他机器。这样做的目的是我正在编写一个需要连接到不同服务器上的数据的Javascript应用程序,并且我收到Same Origin错误。

I am trying to figure out if its possible to do a Reverse Proxy in IIS that actually hit a different web server end point. I have used it to traverse Ports on the same machine, but never to a different machine. The purpose of this is that I am writing a Javascript application that needs to connect to data on a different server and I am getting Same Origin errors.

注意:不幸的是,更改远程服务器和接受JSONP或CORS的服务不是一个选项。

Note: Unfortunately, changing the remote server and service to accept JSONP or CORS is not an option.

这是使用IIS反向代理进行端口跳转的配置

Here is the config for Port jumping using IIS Reverse Proxy

<system.webServer>      
        <rewrite>
            <rules>
                <rule name="Reverse Proxy to Different Port" stopProcessing="true">
                    <match url="^name/(.*)" />
                    <action type="Rewrite" url="http://localhost:5984/{R:1}" />
                </rule>
            </rules>
        </rewrite>
</system.webServer>


推荐答案

为了完成这项工作,您需要安装在IIS服务器上的应用程序请求路由(AAR)反向代理。之后,将以下内容添加到web.config中:

To make this work, you need to have Application Request Routing (AAR) installed on the IIS server you want to act like the reverse proxy. After that, then add the following into the web.config:

<system.webServer>      
    <rewrite>
        <rules>
            <rule name="Reverse Proxy to Different Port" stopProcessing="true">
                <match url="^name/(.*)" />
                <action type="Rewrite" url="http://[hostname here]:[port number here]/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

这将重定向路径以 name / 到另一台服务器。因此,如果您在远程服务器上寻找 / foo / bar ,则需要Javascript来请求 / name / foo / bar 到配置了反向代理的IIS服务器。

This will redirect any request where the path starts with name/ to the other server. So if you're seeking /foo/bar on the remote server, you would need Javascript to request /name/foo/bar to the IIS server that has the reverse proxy configured.

这篇关于IIS反向代理到不同的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆