How To Setup Nginx Reverse Proxy

Setup Nginx Reverse Proxy

In this tutorial, we will show you how to set up a reverse proxy. For those of you who didn’t know, A Nginx HTTPS reverse proxy is an intermediary proxy service that takes a client request, passes it on to one or more servers, and subsequently delivers the server’s response back to the client. If you have multiple servers, a reverse proxy can help balance loads between servers and improve performance. As a reverse proxy provides a single point of contact for clients, it can centralize logging and report across multiple servers.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step by step to set up a reverse proxy.

Setup Nginx Reverse Proxy

Step 1. First, let’s start by ensuring your system is up-to-date.

Step 2. Installing Nginx on the Linux system.

  • Installing Nginx on CentOS 8 is as simple as typing:
  • Installing Nginx on Ubuntu 20.04 LTS is as simple as typing:

Once the installation is complete, enable and start the Nginx service:

Navigate to http://localhost in your browser to verify that the webserver is running as expected:

Setup Nginx Reverse Proxy

Step 3. Set up and Use NGINX as a Reverse Proxy.

First, follow the below command to disable the virtual host:

We need to create a file within the /etc/nginx/sites-available the directory that contains the reverse proxy information. We can name this reverse-proxy.conf for example:

The important part here is the proxy_pass directive which is essentially telling any requests coming through the Nginx reverse proxy to be passed along to the Apache remote socket 192.168.77.20:80.

Once you’ve added the appropriate directives to your .conf file, activate it by linking to /sites-enabled/ using the following command:

Test the Nginx configuration file:

Lastly, we need to run an Nginx configuration test and restart Nginx to check its performance:

Step 4. Nginx Reverse Proxy using Let’s Encrypt.

Run these commands on the command line on the machine to install Certbot:

Then, run this command to get a certificate and have Certbot edit your Nginx configuration automatically:

The result like below:

Congratulations! You have successfully set up a reverse proxy. Thanks for using this tutorial to set up an Nginx Reverse Proxy on the Linux system. For additional help or useful information, we recommend you to check the official Nginx website.

Nginx Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “Nginx Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!