I have a node js application running successfully on app.example.com on port 4000. Now I want to run another node js application on www.example.com on port 5010. How would I do it?
My attempt. Create two files in sites-available folder. one is www.example.com and one is app.example.com content of the files.
app.example.com
server {
listen 80;
server_name app.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
If I have this one alone. It works.
Now adding
www.example.com
server {
listen 80;
server_name www.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
And both node apps are running on running on forever on respective port. Now it doesn't matter what url I give i.e. app.example.com or www.example.com It gives the same application i.e. Hello World. How do I achieve having two different applications on two different ports?
EDIT It's happening if I give www.example.com:5010, but I want it without having to type 5010. How would I achieve that?
www.example.comandapp.example.comto the same server IP.