How to Install Nginx as a Reverse Proxy with Let's Encrypt SSL on Ubuntu 24.04
If you're running an app on a backend port — Node.js on 3000, a Python app on 8000, or a Docker container — you don't want people hitting that port directly. You want one clean, secure front door. Nginx sits in front o
If you're running an app on a backend port — Node.js on 3000, a Python app on 8000, or a Docker container — you don't want people hitting that port directly. You want one clean, secure front door.
Nginx sits in front of your app, handles the public traffic, and forwards requests to the app running behind it. Pair that with a free Let's Encrypt SSL certificate, and you get a properly secured HTTPS setup.
Step 1: Install Nginx
Update your package list and install Nginx on your Bare Metal Server:
bash
sudo apt update
sudo apt install -y nginx
sudo ufw allow 'Nginx Full'
sudo ufw reload
Step 2: Create the Reverse Proxy Server Block
Create a new file for your domain: sudo nano /etc/nginx/sites-available/yourdomain.com
Paste in a basic reverse proxy configuration (replace 3000 with your app's port):
Nginx
server {
listen 80;
server_name yourdomain.com [www.yourdomain.com](https://www.yourdomain.com);
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable it and reload:
Bash
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 3: Install Certbot and Request SSL
Certbot is the standard tool for requesting Let's Encrypt certificates.
Bash
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d [www.yourdomain.com](https://www.yourdomain.com)
Certbot will automatically rewrite your Nginx block to add SSL directives and set up a systemd timer for auto-renewal.
To read more about troubleshooting 502 Bad Gateway errors or verifying your auto-renewal timers, read the full tutorial here: https://www.eservers.uk/tutorials/howto/nginx-reverse-proxy-lets-encrypt-ssl-ubuntu-24-04/
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.