Special Offers: Up to 75% OFF on Hostinger & High-RAM Contabo Cloud VPS available this month.Compare Plans

How to Set Up Nginx Reverse Proxy with SSL on Ubuntu 24.04 (Complete Blueprint)

Marcus Sterling
Marcus SterlingDevOps & Cloud Engineer
October 02, 2026
•
15 min read
•
4.8 / 5.0
Transparency Notice: This article contains affiliate links to hosting providers like Hostinger and Contabo. If you purchase through our links, we may earn a commission at zero extra cost to you. We only recommend products we personally benchmark and test. Read full disclosure.
How to Set Up Nginx Reverse Proxy with SSL on Ubuntu 24.04 (Complete Blueprint)

Hostinger vs. Contabo: Full Specifications Breakdown

Data verified from our lab benchmarks • Updated for 2026

Feature / Metric
HostingerEditor's Choice UI
ContaboMax RAM Value
Starting Price$2.99 / month (Web) | $4.99 / mo (VPS)$5.50 / month (Cloud VPS S)
vCPU Cores1 to 8 vCPU (Dedicated resources)4 to 12 vCPU (High Core Count)
RAM Memory4 GB to 32 GB6 GB to 64 GB (Gigantic RAM)
Storage Technology50 GB – 400 GB NVMe SSD50 GB NVMe or 300 GB SSD
Traffic / Bandwidth4 TB to 32 TB32 TB Outgoing + Unlimited In
Control Panel & UIhPanel (Ultra Modern & Easy)cPanel, Plesk, Webmin, or CLI
Customer Support24/7 Live Chat & AI Support (Multi-lingual)Email Ticket Support (German Business Hours)
Best ForBloggers, WordPress Sites & Devs wanting easy UIHeavy Database, Docker, Game Servers & SysAdmins
Money-Back Guarantee30-Day Money-Back Guarantee14-Day EU Statutory Cancellation
Official LinksVisit HostingerVisit Contabo

What is a Reverse Proxy and Why is Nginx the Best Choice?

A reverse proxy sits between public client connections and private backend application servers (such as a Next.js frontend running on port 3000, an Express API on port 5000, or a FastAPI Python backend on port 8000). Nginx handles TLS certificate negotiation, HTTP/2 multiplexing, static asset caching, and request buffering, isolating your application runtime from direct Internet attacks.

Step 1: Installing Nginx on Ubuntu 24.04

sudo apt update
sudo apt install -y nginx

Step 2: Creating a Production Reverse Proxy Virtual Host

Create a dedicated virtual host configuration in /etc/nginx/sites-available/api.example.com:

sudo nano /etc/nginx/sites-available/api.example.com

Add the following production configuration with proxy buffering and WebSocket upgrades:

# Upstream pool pointing to local application backend
upstream backend_app {
    server 127.0.0.1:3000;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name api.example.com;

    # Redirect all plain HTTP traffic to secure HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name api.example.com;

    # SSL Certificate Paths (provisioned by Certbot)
    ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;

    # Reverse Proxy Location Block
    location / {
        proxy_pass http://backend_app;
        proxy_http_version 1.1;

        # WebSocket support
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # Forward authentic client IP and host headers
        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;

        # Timeouts and Buffer Sizes
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
        proxy_buffer_size 128k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;
    }
}

Step 3: Enabling Site and Validating Syntax

sudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 4: Tuning Gzip Compression & Rate Limiting

Enable gzip compression in /etc/nginx/nginx.conf to compress JSON payloads and CSS/JS assets on the fly:

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml image/svg+xml;

Protect against API denial-of-service floods by configuring IP rate limiting in http {} block: limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;.

Frequently Asked Questions (FAQ)

How do I handle 502 Bad Gateway errors in Nginx?

A 502 error indicates Nginx received no response from the upstream application. Verify your backend service (Node.js/Python) is actively running on port 3000 with curl http://127.0.0.1:3000 or pm2 status.

Editorial Verdict: Pros & Cons

What We Love (Pros)

  • Terminates TLS/SSL encryption at the edge, freeing application workers from cryptographic overhead
  • Provides centralized rate limiting, caching, and gzip/brotli compression
  • Full support for bidirectional WebSocket connections

Drawbacks (Cons)

  • Misconfigured proxy buffer sizes can truncate large JSON API responses
#Nginx#Reverse Proxy#SSL#Ubuntu#DevOps
Marcus Sterling

Written by Marcus Sterling

DevOps & Cloud Engineer

Alex and the ServerCraft engineering lab run routine benchmarks on over 25 web hosting providers, maintaining strict objectivity and reproducibility.

Recommended Next Reads