1

I have a node webapp up and running with my nginx on debian squeeze. Now I want to add another one with an own domain but when I do so, only the first app is served and even if I go to the second domain I simply get redirected to the first webapp. Hope you see what I did wrong here:

example1.conf:

upstream example1.com {
    server 127.0.0.1:3000;
}

server {
listen   80;
server_name  www.example1.com;
rewrite ^/(.*) http://example1.com/$1 permanent;
}

# the nginx server instance
server {
    listen 80;
    server_name example1.com;
    access_log /var/log/nginx/example1.com/access.log;

    # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://example1.com;
      proxy_redirect off;
    }
 }

example2.conf:

upstream example2.com {
    server 127.0.0.1:1111;
}

server {
listen   80;
server_name  www.example2.com;
rewrite ^/(.*) http://example2.com/$1 permanent;
}

# the nginx server instance
server {
    listen 80;
    server_name example2.com;
    access_log /var/log/nginx/example2.com/access.log;

    # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://example2.com;
      proxy_redirect off;
    }
 }

curl simply does this:

zazzl:Desktop udo$ curl -I http://example2.com/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.2
Date: Sat, 04 Aug 2012 13:46:30 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://example1.com/

Thanks :)

optikfluffel
  • 121
  • 5
  • The configuration looks OK. Are you sure nginx has actually been reloaded? Do the workers have a post-config-change timestamp? – cjc Aug 04 '12 at 13:44
  • Yes, if I remove a ```;``` in one of them I get an error. I even restarted instead of reloaded. – optikfluffel Aug 04 '12 at 13:51
  • The `curl` is informative: you're catching a redirect. Are there any other active configuration files that would send a 301? – cjc Aug 04 '12 at 13:54

1 Answers1

1

Sorry guys. I just had some sort of DNS-F*ckup here, after deleting my local DNS cache everything worked fine again. Thanks for helping anyway.

optikfluffel
  • 121
  • 5
  • I thought dns was my problem also because it would work fine in private mode. I had to make sure my `server_name` was set to the domain both with `www` and without. This drove me nuts for weeks because I would go to one domain and it would show me the wrong app. `server_name yoursite.com www.yoursite.com;` – James M. Lay Nov 30 '14 at 18:13