Назад | Перейти на главную страницу

Настройте nginx для нескольких приложений node.js с собственными доменами

У меня есть веб-приложение узла, работающее с моим nginx на debian squeeze. Теперь я хочу добавить еще один с собственным доменом, но когда я это сделаю, будет обслуживаться только первое приложение, и даже если я перейду во второй домен, я просто перенаправлюсь на первое веб-приложение. Надеюсь, вы видите, что я здесь сделал не так:

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 просто делает это:

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/

Спасибо :)

Извините ребята. У меня здесь был какой-то DNS-F * ckup, после удаления моего локального DNS-кеша все снова работало нормально. В любом случае спасибо за помощь.