NGINX is an open source web server with many use cases, it can be use as a Load Balancer in front of your servers to distribute loads across all instances, or it can be used as a normal web server serving static contents like an Apache web server. In this post, I will discuss one of my favourite use cases of NGINX: Using NGINX as a Reverse Proxy to host many applications in a server. This post is the first part of a two-part article on using NGINX as a Reverse Proxy, the first part will focus on the theory part and the second part will be a follow-along tutorial.
What's a Reverse Proxy to begin with ?
To understand the jargon "Reverse Proxy", first we have to understand the term Reverse and Proxy.
Reverse: To make something opposite of what is was.
Proxy: A Proxy is a machine sitting between your device and the internet, it will route your request to the corresponding server on the internet. Here is a nice picture describing a proxy:
Proxy has many use cases, one of the use cases is to keep the client identity anonymous from the server, since the communication between a client and a server is made via a proxy, the servers will not know which requests come from which clients and vice versa.
A Reverse Proxy is a proxy but instead of sitting in front of clients, it sits in front of servers.
Here is a picture of a Reverse Proxy
In my mind, when I think of a proxy I usually put it in the context of client side while I associate a reverse proxy with the server side.
Using Reverse Proxy as a domain-request gateway
Since a Reverse Proxy sits in front of servers, we can configure it to route request based on domain. Here's a nice picture that depicts my infrastructure setup at the moment:
I'm currently hosting two websites on one server and use domain name to route request with the help of NGINX. Here is the setup of my server:
Application 1: NodeJS application running on port 8080 https://www.tedvuurlshortener.me/
Application 2: PHP application running on port 80 https://lunardocinema.com/
Benefits
There are many benefits when using Nginx as a reverse proxy to route request based on domain name, here's a few:
You can host many applications running on one server and hence save resources.
Nginx is easy to setup via a configs file.
What to look for ?
It can be tempting to put too many applications on one server, this will reduce the performance of individual applications.
Other use cases
NGINX can also be used as a load balancer, APIs gateway and many more. You can imagine NGINX as a black box sitting in front of your servers and derive many use cases from there.
What's next ?
In the subsequent post of the explain to your grandma thread, I will provide a follow-along tutorials on how to setup and deploy your very first website. Stay tuned !!