IT Manager candidate based in Riyadh. 12+ years in IT operations and infrastructure.

Phone

+966 55 973 2392

Website

https://www.islamfathi.com

Address

Riyadh, Saudi Arabia

Social Links

Tutorials

A first Nginx reverse proxy, step by step

A small Nginx config that puts a web app behind a proper front door, with the headers the app needs and a safe way to reload.

A first Nginx reverse proxy, step by step

A reverse proxy sits in front of an application and forwards requests to it. Nginx is a popular choice for this on Debian, and the first version takes only a few lines.

Install and create a site
sudo apt update
sudo apt install nginx
sudo nano /etc/nginx/sites-available/myapp

Put this in the file. It assumes your application listens on port 5000 on the same machine.

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

    location / {
        proxy_pass http://127.0.0.1:5000;
        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;
    }
}

The proxy_set_header lines matter. Without them the application sees every request as coming from 127.0.0.1 and may build wrong links, because it does not know the original host or protocol.

Enable it and check the syntax
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Run nginx -t every time. It catches typos before they take the site down, and reload applies the change without dropping connections.

Add HTTPS

For a public site, Certbot can obtain a free Let's Encrypt certificate and edit the config for you. For an internal service, use a certificate from your own certificate authority. Either way, redirect port 80 to 443 once it works.

When something fails

A 502 Bad Gateway means Nginx could not reach the application, so check that it is running and listening on the port you wrote. The error log at /var/log/nginx/error.log usually names the reason in one line.

2 min read
Apr 28, 2026
By Islam Fathy
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Oct 06, 2026 • 1 min read
Automating Repetitive IT Tasks with PowerShell and C#

How small scripts and simple tools save IT teams hours every week, and where to start.

Sep 29, 2026 • 2 min read
SPF, DKIM and DMARC in plain terms

Three DNS records decide whether your email is trusted. What each one does, an example of each, and...

Aug 18, 2026 • 2 min read
DNS problems you can diagnose in five minutes

Many network is down tickets are DNS. A few commands and one question tell you whether the name or t...

Your experience on this site will be improved by allowing cookies. We use cookies to enhance performance and improve your browsing experience. Cookie Policy