简体   繁体   English

IIS AAR - 用于反向代理的URL重写 - 如何发送HTTP_HOST

[英]IIS AAR - URL Rewrite for reverse proxy - how to send HTTP_HOST

Trying to use AAR as a reverse proxy in front of several back end IIS servers. 尝试在几个后端IIS服务器前使用AAR作为反向代理。

  • One public ip address assigned to the server running IIS/AAR 分配给运行IIS / AAR的服务器的一个公共IP地址

  • Then outbound URL rewrite rules are setup to redirect to one of several back end servers depending on hostname. 然后设置出站URL重写规则,以根据主机名重定向到多个后端服务器之一。

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. 有点工作,但总是返回后端服务器默认站点(不是映射到主机名的站点),所以看起来主机名(HTTP_HOST)没有从代理服务器传递到后端服务器。

(I've verified bypassing the reverse proxy by editing hosts and the back end server returns the correct site bound to the host header) (我已通过编辑主机验证绕过反向代理,后端服务器返回绑定到主机头的正确站点)

This is an example of the rule (192.168.0.99 is the internal server, site.myco.com is the hostname) 这是规则的一个示例(192.168.0.99是内部服务器,site.myco.com是主机名)

    <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? 但是唉总是返回默认绑定 - 任何想法?

This post has the answer - Modifying headers with IIS7 Application Request Routing 这篇文章有答案 - 使用IIS7应用程序请求路由修改标头

Need to enable preserveHostHeader - can't see how you do that in the UI but this works 需要启用preserveHostHeader - 无法看到你在UI中如何做到这一点,但这是有效的

Run this from command line to update Machine/webroot/apphost config 从命令行运行此命令以更新Machine / webroot / apphost配置

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true /commit:apphost

My guess would be that your server doesn't allow you to change the server variable HTTP_HOST when you rewrite the URL. 我的猜测是,当您重写URL时,您的服务器不允许您更改服务器变量HTTP_HOST

At the level of the website where the URL rewrite is applied: 在应用URL重写的网站级别:

INETMGR

Then click the Add... link on the right tab and add your HTTP_HOST variable: 然后单击右侧选项卡上的Add...链接并添加HTTP_HOST变量:

添加HTTP_POST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM