June 16, 2020
4min Read
Edward S.
In the Linux operating system, a Reverse Proxy acts as a link between the host (client) and the server. It takes up client requests and passes them on to other servers and finally delivers the server’s response to the client, appearing as if they originated from the proxy server itself. In this tutorial, we’ll show you what an Nginx reverse proxy is and how to set it up on your VPS!
The client and server exchange information continuously to work efficiently. Typically, reverse proxies are used by a web server. A reverse proxy or gateway appears to the client just like an ordinary web server, where no special configurations are necessary. The client makes ordinary requests while the reverse proxy decides where to pass on the information delivering the final output to the client as if it were the origin.
The Nginx reverse proxy has a wide range of benefits. It is amongst the most actively used open-source servers on the internet.
Upgrade your Linux VPS Hosting and try out Nginx reverse proxy today!
Let’s delve into the reasons explaining why this tool is so popular:
And all of these benefits are just the tip of the iceberg! The more you use Nginx Reverse Proxy, the more features you will discover!
Important:
First – we need to access our VPS server using SSH. If you’re having trouble, check out the PuTTY tutorial!
Second – as we explain further in the tutorial, you must already have the Apache web server installed and configured for this method to work.
Now, we will configure Nginx in front of an Apache web server. We chose the Apache server because it’s better at handling dynamic content.
So, all the static content will go to Nginx, while the dynamic content goes to Apache. This will improve performance by optimizing the delivery of content based on the handling criteria.
Next, we will define 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 can move onto these steps:
We’ll be using the apt command on Ubuntu 18.04:
sudo apt-get update
sudo apt-get install nginx
Once you have installed Nginx, follow the below command to disable virtual host:
sudo unlink /etc/nginx/sites-enabled/default
After disabling the virtual host, we need to create a file called reverse-proxy.conf within the etc/nginx/sites-available directory to keep reverse proxy information.
For this, we should first access the directory using the cd command:
cd etc/nginx/sites-available/
Then we can create the file using the vi editor:
vi reverse-proxy.conf
In the file we need to paste in these strings:
server { listen 80; location / { proxy_pass http://192.x.x.2; } }
In the above command, the considerable point is the proxy pass is allowing the requests coming through 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 content.
Once completed, simply save the file and exit the vi editor. You can do this by keying in :wq.
To pass information to other servers, you can use the ngx_http_proxy_module in the terminal.
Now, activate the directives by linking to /sites-enabled/ using the following command:
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
Lastly, we need to run an Nginx configuration test and restart Nginx to check its performance. Type the below command to verify the Nginx functioning on the Linux terminal:
service nginx configtest
service nginx restart
Remember, if you receive a failed test, that most likely indicates that Apache was not properly set up.
There are many benefits of setting up an Nginx reverse proxy in the Linux operating system. It can effectively boost performance and enhance security against malware. The Nginx reverse proxy configuration is a simple process in Linux terminal. Although there are a plethora of ways to install and configure it which completely depend upon your requirement, the above tutorial is hassle-free and straightforward to help you get started with a reverse proxy set up.
April 24 2020
One of the simplest and most helpful guided, loved it.
Andrius S.
Replied on April 24 2020
Hey, glad it helped!