IT Manager candidate based in Riyadh. 12+ years in IT operations and infrastructure.
+966 55 973 2392
https://www.islamfathi.com
Riyadh, Saudi Arabia
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 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.
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.
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.
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.
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.
Your email address will not be published. Required fields are marked *