You can use NGINX as a reverse proxy in front of NODEjs.
Home
In this approach you can run several processes with NODEJS, each on a port and set up a subdomain for each processes / API in NGINX, so it is only necessary to leave the standard HTTP port released on the server for external access.
Example:
Website: example.com
Home
API: api.example.com - > NODEJS on port 8888
SIte: example2.com
Home
API: api.example2.com - > NODEJS on port 9999
NGINX Configuration
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;
}
}
link