you can use NGINX as a reverse proxy in front of Nodejs.
In this approach you can run several processes with NODEJS, each in a port and configure in NGINX a subdomain for each process/API, so you only need to leave the standard HTTP port free on the server for external access.
Example:
Site: example.com.br
API: api.exemplo.com.br -> NODEJS at port 8888
Website: exemplo2.com.br
API: api.exemplo2.com.br -> NODEJS on port 9999
Configuration of the NGINX
server {
listen 80;
index index.html;
server_name exemplo.com.br www.exemplo.com.br;
root /usr/share/nginx/html/exemplo.com.br;
location / {
try_files $uri /index.html;
}
}
server {
listen 80;
server_name api.exemplo.com.br;
location / {
proxy_pass http://127.0.0.1:8888;
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;
}
}
server {
listen 80;
index index.html;
server_name exemplo2.com.br www.exemplo2.com.br;
root /usr/share/nginx/html/exemplo2.com.br;
location / {
try_files $uri /index.html;
}
}
server {
listen 80;
server_name api.exemplo2.com.br;
location / {
proxy_pass http://127.0.0.1:9999;
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;
}
}
http://www.devmedia.com.br/usando-nginx-como-proxy-reverso-e-diminuindo-o-consumo-do-servidor/21461
I understand that the simplest thing is to check the
Host:
do request, do not need to install anything else, it is mere input condition. If you need much more complexity, better change technology..– Bacco