IIS AAR - 反向代理的 URL 重写 - 如何发送 HTTP_HOST [英] IIS AAR - URL Rewrite for reverse proxy - how to send HTTP_HOST

查看:40
本文介绍了IIS AAR - 反向代理的 URL 重写 - 如何发送 HTTP_HOST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在多个后端 IIS 服务器前使用 AAR 作为反向代理.

Trying to use AAR as a reverse proxy in front of several back end IIS servers.

  • 分配给运行 IIS/AAR 的服务器的一个公共 ip 地址

  • One public ip address assigned to the server running IIS/AAR

然后设置出站 URL 重写规则以重定向到其中之一几个后端服务器取决于主机名.

Then outbound URL rewrite rules are setup to redirect to one of several back end servers depending on hostname.

有点作用,但总是返回后端服务器的默认站点(不是映射到主机名的站点),所以看起来主机名 (HTTP_HOST) 没有从代理服务器传递到后端服务器.

Works somewhat, but always returns the back end servers default site (not the one mapped to a hostname) so it looks like the host name (HTTP_HOST) is not getting passed from the proxy server to the back end server.

(我已经通过编辑主机验证绕过反向代理,后端服务器返回绑定到主机标头的正确站点)

这是一个规则示例(192.168.0.99 是内部服务器,site.myco.com 是主机名)

This is an example of the rule (192.168.0.99 is the internal server, site.myco.com is the hostname)

    <rewrite>
        <rules>
            <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                <match url="(.*)" />
                <action type="Rewrite" url="http://192.168.1.99/{R:1}" />                   
            </rule>
        </rules>
    </rewrite>

已尝试将服务器变量放入

Have tried putting sever variables so

    <!-- Guessing server.myco.com is hard coded -->
    <serverVariables>
        <set name="HTTP_HOST" value="server.myco.com" />
    </serverVariables>

    <!-- Guessing picked up dynamically from incoming request host header -->
    <serverVariables>
        <set name="HTTP_HOST" value="{HTTP_HOST}" />
    </serverVariables>

但是唉总是返回默认绑定 - 有什么想法吗?

But alas always returns the default binding - any ideas?

推荐答案

这篇文章有答案 - 使用 IIS7 应用程序请求路由修改标头

需要启用preserveHostHeader - 在用户界面中看不到你是如何做到的,但这有效

Need to enable preserveHostHeader - can't see how you do that in the UI but this works

从命令行运行它以更新 Machine/webroot/apphost 配置

Run this from command line to update Machine/webroot/apphost config

%windir%system32inetsrvappcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true /commit:apphost

这篇关于IIS AAR - 反向代理的 URL 重写 - 如何发送 HTTP_HOST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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