I have two different Nodejs application and say I have app1.example.com and app2.example.com subdomain!
How do I always listen for two subdomains in port 80? I cannot find any sources to do it. Any good tutorial or lead!
I found this :
{
"apps" : [{
"name" : "worker",
"script" : "./worker.js",
"watch" : true,
"env": {
"NODE_ENV": "development"
},
"env_production" : {
"NODE_ENV": "production"
}
},{
"name" : "api-app",
"script" : "./api.js",
"instances" : 4,
"exec_mode" : "cluster"
}]
}
But I didn't understand how can I run both projects on port 80.
Basically, you can run your projects on different ports (not 80) and use an nginx/apache reverse proxy in front of your applications to map them on port 80.
Here is example Nginx configuration:
server {
listen 80;
server_name meantodo.com;
location / {
proxy_pass http://127.0.0.1:1337;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
That will make your nodeJS application on port (1337) available on port 80. You can add multiple location blocks for different subdomains, etc.
Or you can use the Node.JS Reverse Proxy: https://github.com/nodejitsu/node-http-proxy