Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
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 (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

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer
I knew I had to do something with headers :). Thanks! –  yojimbo87 Oct 20 '12 at 13:09
All I wanted was to know that requests are arriving to your iis, then I noticed the host issue :) Glad you fixed it. –  Hex Oct 20 '12 at 13:22
  • 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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.