1

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!

yojimbo87
  • 672
  • 5
  • 12
  • 22
  • Your configuration looks fine. But I have just few dumb questions: 1. Is sub.foo.bar pointing to nginx ip? 2. Did you restart nginx after doing modifications? – Hex Oct 20 '12 at 11:56
  • @Hex: 1. Yes, sub.foo.bar is pointing to nginx and seems to be served correctly by it. 2. Yes. ; It seems to me that what is forwarded to IIS is still sub.foo.bar and not sub-1.foo.bar. I'm not sure if I need to rewrite some headers or something in order to achieve that. – yojimbo87 Oct 20 '12 at 12:02
  • Can you add access_log and error_log directive in your server block and see what is going on through logs? your headers are fine. – Hex Oct 20 '12 at 12:05
  • @Hex: There are no errors in error.log file and access.log contains these (http://pastebin.com/0Yku0mBX) entries when accessing sub.foo.bar – yojimbo87 Oct 20 '12 at 12:17
  • Can you please check if your request is going to your IIS by doing: ngrep -q "^GET" – Hex Oct 20 '12 at 12:20
  • @Hex: I checked the requests going to windows machine with tcp dump and they are present there but that's where they seem to be "lost" after. IIS doesn't log them unless it's binding is also set to sub.foo.bar – yojimbo87 Oct 20 '12 at 12:28

2 Answers2

2
  • 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.

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • I'm aware of that, but what I want to achieve is sub.foo.bar to be processed by nginx which forwards requests to sub-1.foo.bar processed by IIS. – yojimbo87 Oct 20 '12 at 12:33
  • OK, so you have your answer. Did you have another question? – Michael Hampton Oct 20 '12 at 12:34
  • Adding IIS binding to handle sub.foo.bar is currently a workaround not solution. I want the website on IIS to be bound only to sub-1.foo.bar – yojimbo87 Oct 20 '12 at 12:38
2

Try to manually add proxy_set_header Host "sub-1.foo.bar"

Hex
  • 1,949
  • 11
  • 17