20

I'm using IIS7 Application Request Routing in front of Tomcat as a replacement for ISAPI redirection. The basic reverse proxy function is working well, but I don't have enough information in the final request headers. My application exists on several subdomains: customerone.ourservice.com, customertwo.ourservice.com, etc. Each subdomain runs the same application, but with different branding graphics.

The application currently looks at the Host header to tell which branding to display. When I use the IIS7 reverse proxy, that information is lost. My headers are now:

accept = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
accept-charset = ISO-8859-1,utf-8;q=0.7,*;q=0.7
accept-encoding = gzip,deflate
accept-language = en-gb,en;q=0.7,en-us;q=0.3
cookie = JSESSIONID=......
host = 127.0.0.1:8080
max-forwards = 10
user-agent = Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.0.15) Gecko/2009102815 Ubuntu/9.04 (jaunty) Firefox/3.0.15
x-original-url = /
x-forwarded-for = [iis7ip]:47567
x-arr-log-id = affbf81c-a5cf-4212-a43b-901cd9adcee6
connection = Keep-Alive

Is there any way I can insert the original Host header into the request headers passed on by the reverse proxy?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Adrian Cox
  • 6,204
  • 5
  • 41
  • 68
  • I don't now, but I've noticed that in our environment our headers are swapped out by IIS7 for application/xhtml+xml for no good reason. – furtive Jan 29 '10 at 22:04

2 Answers2

46

Application Request Routing has an option to preserve the original host header: preserveHostHeader. This option is by default false. You can enable it with:

"C:\Windows\System32\inetsrv\appcmd.exe" set config -section:system.webServer/proxy /preserveHostHeader:"True" /commit:apphost
BraveNewMath
  • 8,090
  • 5
  • 46
  • 51
Atacan
  • 948
  • 9
  • 10
  • Thanks. I'm not able to test this any more (the application was decommissioned a few months ago), but your answer looks like the correct way to do this and I'm accepting it. – Adrian Cox Aug 25 '11 at 08:03
  • +1 - I had a similar issue with hosted YouTrack instance and this solved a problem with OpenID login not working – Jakub Konecki Jul 08 '12 at 21:19
  • 3
    Anyone know why this only works in the `ApplicationHost.config` and not in each individual `web.config`?? – Steven de Salas Jan 28 '16 at 22:51
  • note that appcmd.exe is in %systemroot%\system32\inetsrv\ (use full path or add it to your Paths variable) more about this here http://www.iis.net/learn/get-started/getting-started-with-iis/getting-started-with-appcmdexe – BraveNewMath Jun 09 '16 at 14:19
  • @StevendeSalas, it seems due to `
    ` -- especially the `overrideModeDefault="Deny"` part.
    – Bagus Tesa Oct 20 '17 at 07:35
  • Thanks! I have a wordpress site behind a reverse proxy and all links using rewrite failed until I applied this command. Instant solution. Seldom it goes this smoothly. – Dennis Jan 14 '19 at 12:49
2

You could set the preserveHostHeader flag by hand.

    <proxy enabled="true" preserveHostHeader="true" />

</system.webServer>

In the iis configuration gui you can find this value under system.webServer/proxy.

enter image description here

hdev
  • 6,097
  • 1
  • 45
  • 62
  • 1
    i updated the file at this location per this answer and it didn't work. Then I ran this command C:\Windows\System32\inetsrv>appcmd.exe set config -section:system.webServer/prox y /preserveHostHeader:"True" /commit:apphost Which ended up fixing the issue. It gives a nice feedback when you run it: Applied configuration changes to section "system.webServer/proxy" for "MACHINE/W EBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST" – BraveNewMath Jun 09 '16 at 14:23