Signup/Sign In

How to Setup A Nginx Reverse Proxy


In the Linux operating system, a Reverse Proxy operates as a connection between the host (client) and the server. It gathers up client requests and passes them on to other servers, and eventually gives the server’s answer to the client, looking as though they came from the proxy server itself. In this guide, we’ll teach you what an Nginx reverse proxy is and how to set it up on your VPS!

The client and server exchange information continually to function effectively. Typically, reverse proxies are utilized by a web server. A reverse proxy or gateway looks to the client precisely like a regular web server, where no additional settings are required. The client performs typical queries while the reverse proxy selects pass on the information providing the final result to the client as if it were the origin.

The Nginx reverse proxy provides a wide variety of features. It is of the most regularly used open-source servers on the internet.

How to Set Up an Nginx Reverse Proxy?

Now, we will set up Nginx in front of an Apache webserver. We picked the Apache server since it’s better at managing dynamic material.

So, all the inert material will go to Nginx, while the dynamic content gets to Apache. This will increase performance by optimizing material delivery depending on the handling criteria.

Next, we will specify the IP address of the Nginx Proxy Server as 192.x.x.1 and the back-end Apache server as 192.x.x.2. After setting up Apache, we may go onto these steps:

1. Install Nginx

We’ll be using the apt command on Ubuntu 18.04:

sudo apt-get update
sudo apt-get install nginx

2. Disable the Default Virtual Host

Once you have installed Nginx, run the following command to deactivate the virtual host:

sudo unlink /etc/nginx/sites-enabled/default

3. Create the Nginx Reverse Proxy

After deactivating the virtual host, we need to create a reverse-proxy file.conf inside the etc/Nginx/sites-available directory to preserve reverse proxy information.

For this, we need first enter the directory using the cd command:

cd etc/nginx/sites-available/

Then we may create the file using the vi editor:

vi reverse-proxy.conf

In the file we need to put in these strings:

server {
    listen 80;
    location / {
        proxy_pass http://192.x.x.2;

In the preceding command, the noteworthy point is the proxy pass enables the requests arriving via the Nginx reverse proxy to pass along to 192.x.x.2:80, which is Apache remote socket. Thus, both the web servers - Nginx and Apache shares the material.

Once done, save the file and close the vi editor. You may achieve this by keying in wq.

To transfer information to other servers, you may use the ngx http proxy module in the console.

Now, activate the directives by connecting to /sites-enabled/ with the following command:

sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf

4. Test Nginx and the Nginx Reverse Proxy

Lastly, we need to run a Nginx configuration test and restart Nginx to assess its performance. Type the following command to validate the Nginx operating on the Linux terminal:

service nginx configtest

service nginx restart

Remember, if you obtain a failed test, it likely implies that Apache was not correctly set up.


Setting up an Nginx reverse proxy on the Linux operating system has several advantages. It may efficiently raise speed and strengthen protection against viruses. The Nginx reverse proxy setting is a straightforward operation in the Linux terminal. Although there are various methods to install and configure it, which entirely depend upon your demand, the following instruction is hassle-free and easy to assist you to get started with a reverse proxy setup.