VPS Malaysia Blog

General

How To Configure Nginx as a Reverse Proxy

Nginx as a reverse proxy sits in front of backend applications, receives public traffic, forwards requests to app ports, handles HTTPS, adds headers, enables caching and can distribute load across servers.

3D reverse proxy gateway routing browser traffic to backend app servers with SSL and cache layers
443Public HTTPS traffic terminates at Nginx
3000Typical backend app port behind proxy
502Common signal that backend routing needs checking

Reverse Proxy Blueprint

What this guide covers.

3D reverse proxy gateway routing browser traffic to backend app servers with SSL and cache layersProxy Gateway

Nginx as a reverse proxy sits in front of backend applications, receives public traffic, forwards requests to app ports, handles HTTPS, adds headers, enables caching and can distribute load across servers.

A reverse proxy hides backend services and gives one public entry point for web traffic.

Core setup includes installing Nginx, creating a server block, proxy_pass, proxy headers, config testing and reload.

Production setup should add SSL/TLS, firewall rules, timeouts, optional load balancing, caching and troubleshooting checks.

Redesigned Guide

Visual decision path.

Reverse Proxy Role

Clients talk to Nginx, not directly to the backend app. Nginx forwards traffic internally while managing public HTTP and HTTPS behavior.

Routes requests to backend appsHides internal portsHandles SSL terminationSupports path-based routingAdds compression and caching

Ubuntu Setup

A typical Ubuntu setup starts with package updates, Nginx installation, service enablement, status checks and firewall allowance.

Use Ubuntu 20.04, 22.04 or 24.04Install Nginx packageStart and enable serviceVerify service statusAllow HTTP/HTTPS through UFW

Server Block

The server block defines domain routing and the proxy_pass target. sites-available stores config; sites-enabled activates it with a symlink.

Create site configSet server_nameProxy to localhost app portPass Host and client IP headersTest config before reload

Production Enhancements

After the basic proxy works, add TLS, timeouts, cache behavior, load balancing and troubleshooting workflows for 502 or 504 errors.

Certbot for Let's EncryptTimeout tuningUpstream blocks for load balancingProxy cache pathCheck logs for backend failures

Quick Reference

Nginx Reverse Proxy Setup Table

Install

Update packages, install Nginx and enable the service.

Configure

Create a server block with server_name and proxy_pass.

Headers

Forward Host, X-Real-IP and X-Forwarded-For correctly.

Secure

Use Certbot and redirect HTTP to HTTPS.

Scale

Add upstream blocks for multiple backend servers.

Troubleshoot

502 means backend unreachable; 504 means timeout or slow upstream.

Nginx is a production gateway: keep the backend private, expose one clean HTTPS entry point, test config before reloads and monitor logs after every change.

Explore VPS Malaysia Services