Nginx reverse proxy and IIS

13,362

Solution 1

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

Solution 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.

Share:
13,362

Related videos on Youtube

yojimbo87
Author by

yojimbo87

2B || !2B, that is the statement.

Updated on September 18, 2022

Comments

  • yojimbo87
    yojimbo87 almost 2 years

    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!

    • Hex
      Hex over 11 years
      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?
    • yojimbo87
      yojimbo87 over 11 years
      @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.
    • Hex
      Hex over 11 years
      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.
    • yojimbo87
      yojimbo87 over 11 years
      @Hex: There are no errors in error.log file and access.log contains these (pastebin.com/0Yku0mBX) entries when accessing sub.foo.bar
    • Hex
      Hex over 11 years
      Can you please check if your request is going to your IIS by doing: ngrep -q "^GET"
    • yojimbo87
      yojimbo87 over 11 years
      @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
    yojimbo87 over 11 years
    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.
  • Michael Hampton
    Michael Hampton over 11 years
    OK, so you have your answer. Did you have another question?
  • yojimbo87
    yojimbo87 over 11 years
    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
    yojimbo87 over 11 years
    I knew I had to do something with headers :). Thanks!
  • Hex
    Hex over 11 years
    All I wanted was to know that requests are arriving to your iis, then I noticed the host issue :) Glad you fixed it.