javascript - IIS反向代理到不同的服务器

标签 javascript iis web-config reverse-proxy windows-server

我试图弄清楚是否可以在 IIS 中执行反向代理来实际访问不同的 Web 服务器端点。我用它来遍历同一台机器上的端口,但从未使用过不同的机器。这样做的目的是,我正在编写一个 Javascript 应用程序,需要连接到不同服务器上的数据,但我收到了同源错误。

注意:遗憾的是,无法更改远程服务器和服务以接受 JSONP 或 CORS。

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

<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>

最佳答案

要实现此功能,您需要 Application Request Routing (AAR)安装在您想要充当反向代理的 IIS 服务器上。之后,将以下内容添加到 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 向具有反向代理的 IIS 服务器请求 /name/foo/bar配置完毕。

关于javascript - IIS反向代理到不同的服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16286421/

相关文章:

asp.net - 在 web.config 中使用 web.config 变量

php - W7 Pro IIS 7.5 覆盖 PHP 位置 : Header

c# - 当 web.config 设置为 Forms 时,AuthenticationSection.Mode 返回 Windows

javascript - 防止空格键和箭头键滚动网页?

javascript - 为什么 Web 加密 SHA-256 会加密消息,而 SHA-512 有时会失败?

javascript - 表单验证 - 使用 Javascript 进行复选框

javascript - 地理定位 - 检查某个位置是否属于某个区域

asp.net - 你如何在本地主机上使用 https/SSL?

.Net Core 主机进程 Windows 2016 IIS 中的高 CPU 使用率在 Asp.Net Core 2.2 应用程序中

iis - AWS Beanstalk IIS 实例和强制 SSL