A reverse proxy sits in front of one or more backend application servers, forwarding client requests and returning responses. Nginx makes an excellent reverse proxy — lightweight, fast, and easy to configure. This guide sets up Nginx as a reverse proxy on Ubuntu 24.04 LTS.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • Nginx installed
  • A backend application running on a local port (e.g., Node.js on :3000)

Step 1 – Understand the Architecture

Traffic flow: Client → Nginx (port 80/443) → Backend app (e.g., localhost:3000). Nginx forwards the request and returns the response to the client.

Step 2 – Create a Server Block for the Proxy

Create a new site config:

sudo nano /etc/nginx/sites-available/myapp

Add a basic reverse proxy configuration:

server {
    listen 80;
    server_name myapp.example.com;

    location / {
        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_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;
    }
}

Step 3 – Enable the Site

Create the symlink:

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/

Step 4 – Test and Reload Nginx

Validate and apply:

sudo nginx -t
sudo systemctl reload nginx

Step 5 – Add SSL with Certbot

Secure the proxy with Let’s Encrypt:

sudo certbot --nginx -d myapp.example.com

Step 6 – Configure Proxy Timeouts (optional)

For long-running requests, increase timeouts inside the location block:

proxy_read_timeout  60s;
proxy_connect_timeout 60s;
proxy_send_timeout  60s;

Step 7 – Enable Gzip Compression

Add to /etc/nginx/nginx.conf inside the http block:

gzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 1000;

Conclusion

Nginx is now acting as a reverse proxy on Ubuntu 24.04 LTS, forwarding requests to your backend application. Add SSL, caching, and rate limiting as your needs grow.