You are currently viewing How to set Up NGINX Reverse Proxy Like a Pro in 10 Minutes?

How to set Up NGINX Reverse Proxy Like a Pro in 10 Minutes?

Hands-on Lab: Quick & Easy Guide to Set Up NGINX Reverse Proxy

NGINX reverse proxy is one of the most powerful yet lightweight solutions for managing modern web traffic. Whether you’re hosting microservices, securing APIs, or scaling backend applications, understanding how to configure an NGINX reverse proxy is a must-have skill for developers, DevOps engineers, and sysadmins. In this hands-on lab, you’ll learn how to set it up from scratch, explore real-world examples, and walk away with a working configuration in minutes.


📚 Table of Contents


💡 Introduction to NGINX Reverse Proxy

NGINX (pronounced “engine-x”) is a high-performance web server often used as a reverse proxy, load balancer, or API gateway.

A reverse proxy accepts client requests, forwards them to backend servers, and returns the response.

Whether you’re hosting websites, APIs, or internal services—NGINX is a powerful, lightweight solution you can set up in under 10 minutes.


🌐 Why Use NGINX Reverse Proxy?

Benefits of using NGINX as a proxy:

  • Load balancing across multiple backend servers
  • SSL termination for secure HTTPS support
  • Caching for better performance
  • Rate limiting and security filtering
  • Single-entry gateway for microservices

👉 It improves scalability, performance, and security in modern DevOps and cloud-native environments.


🧰 Prerequisites for Nginx Reverse Proxy Lab:

Before starting, make sure you have:

  • ✅ A Linux server (Ubuntu/Debian or RHEL/CentOS)
  • ✅ Root or sudo privileges
  • ✅ Terminal access (SSH or local)

🔧 Step-by-Step Guide to Set Up NGINX Reverse Proxy

1. Install NGINX

For Ubuntu/Debian:

sudo apt update
sudo apt install nginx -y

For CentOS/RHEL:

sudo yum install epel-release -y
sudo yum install nginx -y
sudo systemctl enable nginx

2. Backup Default Config

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup

3. Create Custom Proxy Config

Edit your main config or add a new one in /etc/nginx/conf.d/.

sudo nano /etc/nginx/conf.d/proxy.conf

Paste the following:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Replace localhost:3000 with your backend app or API.


4. Reload and Test NGINX

sudo nginx -t    # Test config
sudo systemctl reload nginx

🧾 Example nginx.conf

Here’s a clean nginx.conf if you prefer single-file management:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout 65;

    server {
        listen 80;
        server_name localhost;

        location / {
            proxy_pass http://127.0.0.1:5000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

✅ Verify Nginx Reverse Proxy Setup

Visit http://your-server-ip/ in your browser.

If everything is configured correctly, you’ll see your backend app served via NGINX.

Pro tip: Use curl -I http://localhost to test HTTP response headers.


 Real-World Use Cases of Nginx Reverse Proxy

  • Hosting React/Angular frontend with API backend
  • Central gateway for microservices
  • Rate-limiting public-facing APIs
  • SSL termination for Kubernetes ingress controllers

Want to learn Kubernetes ingress too? Read Beginner’s Guide to Kubernetes Ingress.


🛠️ Troubleshooting Tips

  • Port in use? Run sudo lsof -i :80 to check conflicts
  • NGINX not starting? Check sudo nginx -t for config errors
  • App unreachable? Verify proxy_pass IP and port

📌 Best Practices

  • Use proxy_set_header to preserve original IP
  • Use SSL (listen 443 ssl) and Certbot for HTTPS
  • Split config into /etc/nginx/conf.d/ for modularity
  • Monitor NGINX logs:
    sudo tail -f /var/log/nginx/access.log
    

🔁 NGINX Proxy vs NGINX Reverse Proxy: What’s the Difference?

Understanding the difference between a forward proxy and a reverse proxy is essential in modern networking and DevOps.


🔹 Nginx Forward Proxy (NGINX as a simple Proxy)

  • Client is hidden from the destination
  • Used to access external resources (like the internet)
  • Commonly used in corporate firewalls or content filtering
Client → NGINX Proxy → Internet

🔹 Nginx Reverse Proxy (NGINX as Reverse Proxy)

  • Backend servers are hidden from the client
  • NGINX handles incoming traffic and forwards it to internal servers
  • Common in web hosting, microservices, API gateways
Client → NGINX Reverse Proxy → Backend Servers

📷 Image below illustrates the difference:

cicdtrail.com - NGINX Proxy vs NGINX Reverse Proxy


🎯 Conclusion & Next Steps

Setting up an NGINX proxy is easy, powerful, and a must-have skill in DevOps and cloud infrastructure.

Want more labs like this? Subscribe to our DevOps Hands-On Labs Newsletter and never miss a tutorial!


✅ Got Questions or Want to work with us or looking for Partnership?

💬 Have questions or stuck during setup? Drop a comment below or connect with us on LinkedIn.
🔁 Share this post with fellow DevOps engineers and help them master NGINX.
🔔 Bookmark CICDTrail.com for more high-quality DevOps tutorials.


🔗 Related Articles


🌐 External References

Spread the love

team_cicdtrail

Only for Editorials, blogs and articles.

Leave a Reply