7

I would like to host 2 different node applications with nginx from the same domain and am having some trouble. I would like to have:

mydomain.com point to node app firstApp and otherapp.mydomain.com point to node app otherapp

Right now, I can access firstApp just fine, but I cannot access otherapp via otherapp.mydomain.com.

My config for firstApp looks like this:

upstream firstApp{
 server 127.0.0.1:8123;
}
server{
 server_name mydomain.com;
 access_log /var/log/nginx/me.log;
 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://firstApp/;
 proxy_redirect off;
 }
}

My config for otherapp looks like this:

upstream otherapp{
 server 127.0.0.1:8124;
}
server{
 server_name otherapp.mydomain.com;
 access_log /var/log/nginx/me.log;
 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://otherapp/;
 proxy_redirect off;
 }
}

I have created both configurations in the nginx sites-available directory, they are both linked in the sites-enabled directory, and I have restarted nginx. Can someone tell me what I'm doing wrong?

Thanks, Swaraj

asked Aug 13, 2013 at 0:48

3 Answers 3

4

Just found out what the problem was. Though my nginx configs were correct, I had not added my desired subdomain to my domain name provider (namecheap). I added my subdomain on namecheap, and everything is working correctly now.

answered Aug 13, 2013 at 1:24
Sign up to request clarification or add additional context in comments.

Comments

3

you should config your nginx file like this

server {
 listen 80; 
 server_name biger.yourdomain.cn;
 access_log /data/log/nginx/access_ab.log;
 error_log /data/log/nginx/error_ab.log;
 location /firstApp {
 proxy_store off;
 proxy_redirect off;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header Host $http_host;
 proxy_pass http://localhost:8001/;
 }
}

maeby you need add this code to your project

app.enable('trust proxy');
Diego Rafael Souza
5,3243 gold badges27 silver badges65 bronze badges
answered Apr 26, 2014 at 3:23

Comments

2

I was facing the same problem, after spending time on research I wrote a blogpost where I explained with details how I solved it, I hope it helps. Here it is: http://blog.donaldderek.com/2013/08/cf-i-configure-your-staging-machine-with-node-js-and-nginx/

answered Sep 2, 2013 at 11:42

1 Comment

The link is dead.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.