Install nginx reverse proxy to listen on default port
sudo apt install nginx
edit the /etc/nginx/sites-available/default file. Find the server_name and location lines and replace with these
server_name yourdomain.com www.yourdomain.com;location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. proxy_pass http://localhost:8000; #or your app 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;}
# To run two sepearte backend on two different domainserver { listen 80; server_name abc.com; location / { proxy_pass http://localhost:3000; # First backend on port 3000 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }}server { listen 80; server_name xyz.com; location / { proxy_pass http://localhost:4000; # Second backend on port 4000 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }}
# Install Certbotsudo snap install --classic certbot# Prepare the Certbot commandsudo ln -s /snap/bin/certbot /usr/bin/certbot# Run this command to get a certificatesudo certbot --nginx# Test automatic renewalsudo certbot renew --dry-run