10 Feb 2019

Simple Way to Configure Nginx Reverse Proxy

Overview

A reverse proxy is a server that takes incoming HTTP/HTTPS requests and transfers or distributes them to a backend server. Backend servers can be application servers like Tomcat or Wildfly, or other web servers like Apache.

Why use a reverse proxy?

  1. Security — hides the origin server, making backend servers less exposed to direct attacks.
  2. Encryption/decryption — handles request encryption, reducing load on backend servers.
  3. Caching — can cache content to reduce server load.
  4. Load balancing — can distribute traffic across multiple servers.

Prerequisites

You need a backend server (application or web server). This example uses an Apache Tomcat server at 192.168.1.110 on port 8080. If you’re running another web server on the same machine as Nginx, make sure they don’t share the same TCP ports (80 or 443).

Configuration

Remove the default configuration:

# rm /etc/nginx/conf.d/default.conf

Create a new configuration file:

# vi /etc/nginx/conf.d/test-proxy.conf

Add this configuration:

upstream appserver {
     server 192.168.1.110:8080;
}
server {
     listen 80;
     listen [::]:80;
     server_name test-reverse-proxy.com;
     location / {
           proxy_pass http://appserver;
     }
}

Validation and restart

# nginx -t
# systemctl restart nginx

Testing

Visit the Nginx server’s address in a browser — you should see the Apache Tomcat page instead of the default Nginx page, confirming the reverse proxy is working.