Why Use a Reverse Proxy?
When hosting web applications built with Node.js, Next.js, Python FastAPI, or Docker containers, directly binding app processes to port 80/443 exposes your application layer to raw connection floods.
A hardened Nginx reverse proxy acts as an intelligent intermediary that:
Terminates SSL/TLS certificates efficiently.Buffers slow client uploads.Compresses assets using gzip/Brotli.Distributes traffic to internal ports (`localhost:3000`, `localhost:8080`).
Step 1: Install Nginx & Certbot
sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx
Verify that Nginx is active:
sudo systemctl enable --now nginx
Step 2: Configure Server Block
Create a configuration file for your domain at `/etc/nginx/sites-available/edufwesh.conf`:
server {
listen 80;
listen [::]:80;
server_name edufwesh.com.ng www.edufwesh.com.ng;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}
Enable the site and test configuration:
sudo ln -s /etc/nginx/sites-available/edufwesh.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 3: Obtain Automated Free SSL via Certbot
sudo certbot --nginx -d edufwesh.com.ng -d www.edufwesh.com.ng --non-interactive --agree-tos -m edufwesh@gmail.com --redirect
Certbot will automatically modify your Nginx configuration, bind TLS 1.3 certificates, and enable automatic 301 redirects from HTTP to HTTPS!
Verify automatic renewal:
sudo certbot renew --dry-run