Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

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

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.

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

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

like image 718
Ryan Avatar asked Feb 12 '13 21:02

Ryan


3 Answers

This post has the answer - Modifying headers with IIS7 Application Request Routing

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

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

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true /commit:apphost
like image 139
Ryan Avatar answered Nov 09 '22 06:11

Ryan


You can do this with GUI. While on the root server click configuration editor, go to System.webServer -> proxy and set preserveProxyHeader to true.

enter image description here

like image 9
Catch Avatar answered Nov 09 '22 07:11

Catch


My guess would be that your server doesn't allow you to change the server variable HTTP_HOST when you rewrite the URL.

At the level of the website where the URL rewrite is applied:

inetmgr

Then click the Add... link on the right tab and add your HTTP_HOST variable:

add HTTP_POST

like image 2
cheesemacfly Avatar answered Nov 09 '22 05:11

cheesemacfly