How to Configure Nginx as a Reverse Proxy
Dec 4, 2026
Nginx is a popular web server that can also work as a reverse proxy. A reverse proxy receives requests from website visitors and forwards them to another server or application. It then sends the response back to the visitor. This setup is useful when hosting applications such as Node.js, Python or other web services behind Nginx. It also helps manage incoming traffic through a single entry point.
What Is an Nginx Reverse Proxy?
When a visitor opens a website, the request first reaches the Nginx server. Instead of processing the application request directly, Nginx forwards it to the backend application running on another port or server. For example, your Node.js application may run on port 3000, while Nginx listens for public website requests on port 80 or 443. Nginx connects these two services and delivers the application's response to the visitor.
How to Configure Nginx as a Reverse Proxy
Before starting, make sure Nginx is installed and your backend application is running.
1. Open the Nginx Configuration
Access your server through SSH and open the relevant Nginx server block configuration file. The file location depends on your operating system and server setup.
2. Add the Reverse Proxy Settings
Inside the appropriate server block, add a location configuration like this:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
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;
}
}
Replace example.com with your domain name and 3000 with the port used by your application.
3. Test and Apply the Configuration
Save the configuration and check it for errors:
sudo nginx -t
If the test is successful, reload Nginx:
sudo systemctl reload nginx
4. Test Your Website
Open your domain in a browser and check whether the application loads correctly. Also, make sure the backend application is running and accepting connections. For a production website, configure HTTPS using a valid SSL certificate and check that the proxy settings meet your application's requirements.
Why Is Reverse Proxy Configuration Important?
A properly configured reverse proxy can help with:
- Application management: Direct requests to applications running on different ports.
- Traffic handling: Provide a central entry point for incoming website requests.
- Security: Keep backend application services separate from direct public access.
- Scalability: Support setups where requests are distributed across multiple backend servers.
- Performance: Use Nginx features such as response buffering where suitable.
Get Professional Nginx Configuration Support
Configuring Nginx as a reverse proxy requires the correct server settings, application ports, request headers and security configuration. Even small mistakes can cause connection errors or prevent applications from loading. SriLanka Hosting provides Web Server Configuration services covering Apache, Nginx and LiteSpeed optimisation. If you need help configuring a reverse proxy, improving web server settings or preparing your server for application hosting, our technical team can help.
Visit
SriLanka Hosting Server Configuration
to explore our configuration services and get professional support for
your server.