Use a Reverse Proxy Node.js
An NGINX configuration file at /etc/nginx/sites-available/default can define the incoming ports, set the SSL certificates, look for static files, and resolve requests to the Node.js application when a static file isn’t found:
server {
listen 80;
listen 443 ssl;
# live domain
server_name myapp.com;
# HTTPS certificates
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
# static file?
location / {
root /home/node/myapp/static/;
index index.html;
try_files $uri $uri/ @nodejs;
}
# Node.js reverse proxy
location @nodejs {
proxy_pass http://localhost:3000;
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;
}
}