How to install multiple nodejs applications with multiple domains?

I am reading more than ever at this time, this will be my first web page, so I decided to mount on nodejs. I make the application really fast and I am testing in localhost: 9000

so I want to add more applications on VPS, I'm looking for information and I have two options

first use nginx to proxy applications ...

upstream example1.com { server 127.0.0.1:3000; } server { listen 80; server_name www.example1.com; rewrite ^/(.*) http://example1.com/$1 permanent; } # the nginx server instance server { listen 80; server_name example1.com; access_log /var/log/nginx/example1.com/access.log; # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options 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://example1.com; proxy_redirect off; } } 

I do not understand this configuration file because I never use nginx, so I am looking for the second option

using vhost from expressjs ()

 express() .use(express.vhost('m.mysite.com', require('/path/to/m').app)) .use(express.vhost('sync.mysite.com', require('/path/to/sync').app)) .listen(80) 

im using expressjs, and I understand how to configure, but there are some questions about which one is the best option, because with express () I have one application that manages multiple applications, so I believe that this is not good practice and a waste of resources.

from this post, David Ellis says

If you don't need to use WebSockets (or any HTTP 1.1 feature), you can use NginX as a proxy instead.

The advantage is that the overall load that NginX can handle compared to Node is higher (it statically compiles and specializes for these kinds of things, mostly), but you lose the ability to transfer any data (sending smaller chunks at a time).

For a small site, or if you don't know what features you will need in the future, it's probably best to stick with node-http-proxy and only switch to NginX if you can demonstrate a proxy server bottleneck on your server. Fortunately, NginX is not difficult to configure if you need it later.

and this post I read an example of xginx setup with many applications, but I donโ€™t understand how to use this for me

 upstream example1.com { server 127.0.0.1:3000; } server { listen 80; server_name www.example1.com; rewrite ^/(.*) http://example1.com/$1 permanent; } # the nginx server instance server { listen 80; server_name example1.com; access_log /var/log/nginx/example1.com/access.log; # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options 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://example1.com; proxy_redirect off; } } upstream example2.com { server 127.0.0.1:1111; } server { listen 80; server_name www.example2.com; rewrite ^/(.*) http://example2.com/$1 permanent; } # the nginx server instance server { listen 80; server_name example2.com; access_log /var/log/nginx/example2.com/access.log; # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options 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://example2.com; proxy_redirect off; } } 

so the question is the best option, use nginx or use vhost ???

if I need to use nginx, is there some kind of tutorial on how to configure nginx to serve many applications on Node js ???

tnx all

+4
source share
1 answer

Your example for configuring Nginx is what you are looking for. you must create your configuration files in / etc / nginx / sites -available and then create a symlink for the ones you want to include in / etc / nginx / sites -enabled

maybe this will help you - http://blog.dealspotapp.com/post/40184153657/node-js-production-deployment-with-nginx-varnish

+3
source

All Articles