How to host 3 node applications with 3 different domains on one VPS?

I'm stuck trying to set up multiple Node apps on different domains on the same Digital Ocean camera. I followed Host Multiple Node.js Applications on the same VPS with nginx, forever and crontab exactly.

I have all the correct pointers and a set of records.

I can not force applications to run (from forever) on any port other than the standard express 3000.

I changed the Nginx settings as he asked:

I uncommented server_names_hash_bucket_size 64; (as they say)

I created the /etc/nginx/conf.d/example.com.conf files for applications (these are different domains, I put 1 on port 3000 and the other on 4000).

Example:

server {
listen 80;

server_name your-domain.com;

location / {
    proxy_pass http://localhost:{YOUR_PORT};
    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;
}

}

, Nginx ? "npm start"? ?

, . , Node .

+4
2

, : , 3 node, 3000 000 000 000. 3 ip, , example.com, ex1, ex2, ex3, ip. 3 /etc/nginx/sites -enabled/ , ex1.example.com, ex2.example.com, ex3.example.com node nginx. node .

+2

DigitalOcean, Nginx . -, - . Nginx, , 80 .

, . , ? . , - :

PORT=4000 forever start --sourceDir /path/to/your/node/app main.js

, - . , -, :

#!/usr/bin/env node
var debug = require('debug')('my-application');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

3000, .

+6

Source: https://habr.com/ru/post/1539640/


All Articles