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

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 :)

share|improve this question
    
The configuration looks OK. Are you sure nginx has actually been reloaded? Do the workers have a post-config-change timestamp? –  cjc Aug 4 '12 at 13:44
    
Yes, if I remove a ; in one of them I get an error. I even restarted instead of reloaded. –  udo Aug 4 '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 4 '12 at 13:54
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

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.