Nginx reverse proxy and IIS

yojimbo87 asked:

I’m using nginx as a reverse proxy for website running on IIS 7.5. Website is bound to sub-1.foo.bar. Nginx configuration looks like this:

server {
    listen 80;

    server_name sub.foo.bar;

    location / {
        proxy_pass http://sub-1.foo.bar;
        proxy_set_header Host $host;
        proxy_set_header X-Accel-Expires 0;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

What I want to do is forward requests which come to sub.foo.bar (linux machine with nginx) to sub-1.foo.bar (windows machine with IIS and my website). However what happens is

  • when I access sub.foo.bar, I get 404 page
  • when I access sub-1.foo.bar directly I get my website served normally from IIS
  • nginx seems to forward requests normally to windows machine
  • I can’t see any incoming requests from IIS logs when I access sub.foo.bar
  • when I add binding for sub.foo.bar on IIS, website gets proxied normally with nginx

I would appreciate any ideas on what might be wrong with my setup. Thanks!

My answer:


  • when I add binding for sub.foo.bar on IIS, website gets proxied normally with nginx

IIS has to be aware that it should answer requests for the name sub.foo.bar. Otherwise it routes requests to the Default Website. You can fix this by either creating the binding, or by creating/editing your Website to answer for sub.foo.bar.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.