Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Scenario:

First node.js app is running on 127.0.0.1:8888 and serving only one route 'domain.com/track.gif'

Second node.js app is running on 127.0.0.1:3000 and it's a dashboard for stats gathered by the first app and it's avaliable on 'domain.com' (and other routes like 'domain.com/login' or 'domain.com/dashboard', etc)

When I use this config below - only for first app, the first app works great, it serves this tracking gif file when I hit "domain.com/track.gif":

upstream tracker {
  server 127.0.0.1:8888;
}

server {
  listen 0.0.0.0:80;
  server_name www.domain.com domain.com;
  access_log /var/log/nginx/domain_access.log;
  error_log /var/log/nginx/domain_error.log;

  location /track.gif {
    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://tracker;
    proxy_redirect off;
  }
}

How to add another (second) node.js app to this config to take care of the whole routing for routes like 'domain.com/' or 'domain.com/dashboard' or 'domain.com/login'?

Thanks in advance!

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Add a second location block. It will match any path except /track.gif.

upstream tracker {
  server 127.0.0.1:8888;
}

server {
  listen 0.0.0.0:80;
  server_name www.domain.com domain.com;
  access_log /var/log/nginx/domain_access.log;
  error_log /var/log/nginx/domain_error.log;

  location /track.gif {
    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://tracker;
    proxy_redirect off;
  }

  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://127.0.0.1:3000;
    proxy_redirect off;
  }
share|improve this answer
    
Exactly what I needed. Thanks! –  Pono Feb 6 '12 at 19:56

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.