How to Configure NGINX as a Reverse Proxy on Ubuntu 22.04
Posted on: August 20, 2025 | Tags: NGINX, Reverse Proxy, Ubuntu, Web Server, DevOps
🔍 Introduction
A reverse proxy is a type of server that retrieves resources on behalf of a client from one or more backend servers.
It’s commonly used to load balance, secure, or cache content for web apps. NGINX is one of the most powerful tools for reverse proxy setups.
This tutorial will guide you step-by-step on configuring NGINX as a reverse proxy on Ubuntu 22.04.
✅ Prerequisites
- Ubuntu 22.04 LTS Server (Root or sudo access)
- A domain name pointed to your server (e.g.,
example.com
) - Backend application running on another port (e.g.,
http://localhost:5000
)
⚙️ Step 1: Install NGINX
sudo apt update
sudo apt install nginx -y
Enable and start the service:
sudo systemctl enable nginx
sudo systemctl start nginx
🛠️ Step 2: Configure Reverse Proxy
Create a new configuration file for your site:
sudo nano /etc/nginx/sites-available/myapp
Add the following content:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Activate the configuration:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
🔐 Step 3: Secure with Let’s Encrypt SSL (Optional but Recommended)
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com
Auto-renew SSL:
sudo systemctl status certbot.timer
📊 Step 4: Verify Everything
Visit http://example.com
and check if the backend application is loading through NGINX. Run the following to confirm NGINX is listening:
sudo lsof -i -P -n | grep LISTEN
✅ Conclusion
NGINX is a powerful tool for building scalable and secure web infrastructure.
Using it as a reverse proxy enables you to shield backend apps, serve multiple services, and add HTTPS with ease.
If you’re running Docker, Node.js, Flask, or Django apps—this setup will become your go-to deployment pattern.
📌 Need help setting up advanced NGINX configurations?
Drop a comment below or contact the InfraDecoded team for a custom guide.