NGINX Reverse Proxy Setup for Beginners — Step by Step Guide

NGINX Reverse Proxy Setup for Beginners — Step by Step Guide

2026-06-12 DevOps & Tools 9 min read

NGINX Reverse Proxy Setup: A Complete Beginner's Guide

An NGINX reverse proxy is one of the most powerful tools you can deploy on a modern web server, acting as an intermediary that forwards client requests to backend services while shielding your infrastructure from direct exposure. Whether you want to host multiple applications on a single server, terminate SSL connections efficiently, balance traffic across nodes, or support WebSocket connections, mastering the NGINX reverse proxy setup is a foundational skill for any DevOps engineer, system administrator, or full-stack developer. This guide walks you through everything from basic concepts to a complete, production-ready configuration in five clear steps.

What Is a Reverse Proxy and Why Use NGINX?

A reverse proxy is a server that sits between client devices and backend application servers. When a user makes a request, it goes to the reverse proxy first, which then forwards it to the appropriate backend service. The client never communicates directly with the backend, which dramatically improves security, scalability, and performance.

NGINX is one of the most popular web server and reverse proxy choices in the world because it is lightweight, event-driven, and capable of handling tens of thousands of simultaneous connections with minimal memory consumption. Originally designed as a high-performance web server, NGINX evolved into a versatile tool used for proxy setup, load balancing, caching, and media streaming.

Reverse Proxy vs Forward Proxy

Understanding the difference between a forward proxy and a reverse proxy is essential:

Both proxies relay requests, but the direction and purpose differ. A reverse proxy is the tool you want when configuring your own web infrastructure.

Key Benefits of an NGINX Reverse Proxy

Before diving into the configuration, it helps to understand why so many teams rely on this approach.

Prerequisites for the Setup

Before configuring your first NGINX reverse proxy setup, make sure you have the following ready:

Step 1: Install NGINX

The first step in any proxy setup is installing the NGINX web server. On Ubuntu or Debian-based systems, the process is straightforward.

Update your package index and install NGINX with the following commands:

You can verify the installation by visiting your server's public IP address in a browser. You should see the default NGINX welcome page, confirming the web server is running.

Step 2: Configure the Upstream Backend

The upstream directive in NGINX defines a group of backend servers that will receive proxied requests. Open the default configuration file to begin:

Add an upstream block at the top of the file, just above the server block:

This block tells NGINX that requests proxied to backend_app should be distributed between two local application instances. You can add as many backend servers as needed. This is the foundation of load balancing with NGINX.

Step 3: Set Up the Reverse Proxy Block

Inside the server block of the same file, replace the default location configuration with a proxy_pass directive. The proxy_pass instruction is the heart of any NGINX reverse proxy setup.

The proxy_set_header lines pass important client information to the backend, ensuring your application knows the original requester's IP, the requested host, and the protocol used. Without these headers, backend services often lose visibility into the true origin of traffic.

Understanding proxy_pass

The proxy_pass directive tells NGINX where to forward incoming requests. It can point to an upstream block, a specific server, or even a remote URL. When combined with a location block, you can route different URL paths to different backends. For example, you could route /api to one application and /admin to another, all from the same NGINX instance.

Step 4: Enable SSL with Let's Encrypt

SSL is no longer optional in modern web infrastructure. Encrypting traffic between clients and your NGINX reverse proxy protects sensitive data and improves search engine rankings. The easiest way to add a free SSL certificate is by using Certbot and Let's Encrypt.

Certbot will automatically detect your server configuration, request a certificate, and update your NGINX file to redirect all HTTP traffic to HTTPS. It also handles automatic certificate renewal, so you do not have to worry about expiration. This SSL termination at the proxy level is one of the most valuable benefits of using NGINX as a reverse proxy.

Step 5: Test and Reload NGINX

Before applying any configuration changes, always test the NGINX syntax. A single typo can prevent the service from starting, potentially taking your application offline.

If both commands succeed, your NGINX reverse proxy is now live. Visit your domain in a browser, and you should see your backend application loading through the proxy. Check the response headers with browser developer tools to confirm the traffic is flowing correctly through NGINX.

Advanced Configuration: Load Balancing Strategies

One of NGINX's most powerful features is its ability to distribute traffic intelligently. By default, NGINX uses the round-robin algorithm, but you can switch to other strategies based on your application's needs.

These options transform a simple proxy setup into a sophisticated load-balancing solution, capable of handling significant traffic spikes and backend failures.

Adding WebSocket Support

Modern web applications often rely on WebSocket connections for real-time communication. NGINX supports WebSocket proxying with a few additional headers. Inside your location block, add the following directives:

These three lines tell NGINX to upgrade the connection to a WebSocket session, enabling full-duplex communication between the client and the backend. Without them, WebSocket-based applications such as chat platforms, trading dashboards, and live notification systems will fail to maintain persistent connections.

Common Pitfalls and Troubleshooting Tips

Even experienced engineers run into issues during a NGINX reverse proxy setup. Here are the most common problems and their solutions.

Best Practices for Production Deployments

Once your NGINX reverse proxy setup is working, follow these best practices to ensure long-term reliability and performance.

A well-tuned reverse proxy can dramatically improve the resilience of your infrastructure, especially when paired with container orchestration platforms like Docker Swarm or Kubernetes. In those environments, NGINX is often used as an ingress controller, routing external traffic to internal pods and services.

Conclusion

Configuring an NGINX reverse proxy is a high-value skill that pays dividends throughout your DevOps career. From simple proxy setup tasks to complex load balancing and SSL termination, NGINX delivers the performance, flexibility, and security modern web applications demand. By following the five steps outlined in this guide, you can deploy a production-ready reverse proxy that scales with your infrastructure, supports WebSocket connections, and protects your backend services from direct exposure. Start small, test thoroughly, and expand your configuration as your needs grow.

FAQ

What is the difference between proxy_pass and upstream in NGINX?

The upstream directive defines a group of backend servers and how traffic should be distributed among them, including load-balancing algorithms. The proxy_pass directive tells NGINX where to forward incoming requests, either to an upstream block or a specific URL. Together, they form the core of every NGINX reverse proxy configuration.

Can NGINX act as both a web server and a reverse proxy?

Yes. NGINX was originally designed as a high-performance web server and later extended to function as a reverse proxy, load balancer, and mail proxy. In a typical configuration, NGINX serves static files directly while forwarding dynamic requests to backend application servers such as Node.js, Python, or PHP.

How do I enable WebSocket support in an NGINX reverse proxy?

To support WebSocket connections, add proxy_http_version 1.1;, proxy_set_header Upgrade $http_upgrade;, and proxy_set_header Connection "upgrade"; inside the relevant location block. These headers upgrade the HTTP connection to a WebSocket session, allowing real-time bidirectional communication between clients and backend services.

Is NGINX better than Apache for reverse proxy setups?

Both NGINX and Apache can function as reverse proxies, but NGINX's event-driven architecture handles high concurrency more efficiently with lower memory usage. For most modern use cases involving load balancing, SSL termination, and WebSocket support, NGINX is generally the preferred choice for performance-sensitive deployments.

How do I monitor my NGINX reverse proxy?

NGINX provides access and error logs in /var/log/nginx/ by default. For deeper visibility, integrate tools like the NGINX Plus dashboard, Prometheus with the nginx-exporter, or the ELK stack. Monitoring active connections, request rates, and upstream health helps you detect and resolve issues before they affect end users.


Disclaimer: This article is for informational purposes only.

Updated: 2026-06-12 | Prices and availability subject to change.