Heroine.
And welcome back.
So in today's video, we will be discussing about one of the interesting feature of Nginx, which is
that of a reverse proxy based setup.
So at a high level overview, a reverse proxy is a type of proxy server which retrieves the resource
on behalf of a client from one or more servers.
So this can be better understood with the diagram that we have here where you have a internal network
on the right hand side and you have a client on the left hand side.
Now when you discuss about internal network, one of the primary server here is the application server,
which actually hosts the application for your organization and what you have, you have a Nginx server
that is available Now.
What will happen is when a client wants to load the application, what will happen?
The request first goes to the Nginx server here from the Nginx server, it goes to the application server,
it receives the response back from the application server and the response is sent back to the client.
So this type of setup is referred to as a reverse proxy based setup.
And this type of setup provides great amount of advantages, primarily because you have a Nginx that
is sitting between the client and the application server here.
Now a reverse proxy can play a key role in a lot of use cases.
Some of them include it hides the existence of the original back end servers.
For example, Client will never really know what are the IP addresses or what are the application servers
that are running behind the scenes.
Second important thing is that it can protect the back end servers from web based attacks, as well
as denial of service attacks and various others.
So basically what happens, let's say a client wants to bring down the application server so he might
use various kind of attacks, maybe a layer seven attacks like SQL injection, etcetera.
So what you can do is at the Enginex level itself, you can have a tight security control, maybe you
can have a VRF, maybe you can have various denial of service controls, etcetera.
So whatever attack that client is trying to send, it will be controlled at a enginex level itself.
It will never reach your backend application server.
So this is one of the great advantages of reverse proxy based setup.
Along with that, you can also have caching functionality, SSL termination proxy and various others.
So let's do one thing before we discuss more in detail about it.
Let's quickly look into how exactly this setup looks like.
So for today's demo, we have three servers that are available.
First one is the Nginx proxy, second one is the application server.
So very similar to what we were discussing, Nginx proxy here and the application server here.
And third, we have the authentication server which will be discussing at a later part of this video.
So first let's quickly look into this setup that we have discussed till now.
Let's quickly open up the IP address associated with the application server.
Let me paste it within the browser and here you see you have a simple message stating that this is a
application server.
Now we already have a reverse proxy based setup configured, so when a client makes a request to Nginx,
automatically requests will be sent to application server, a response will be received and the response
will be sent back to the client.
So now let's open up the Nginx proxy IP address.
I'll add it here.
And again here you see it states this is a application server.
So now at this stage the client does not really know that the actual response of this is coming from
the backend application server.
The Nginx is hiding that completely.
Here now to quickly show you, I'm currently within the application server and let's do a tail f on
var log nginx access dot log to actually show you that the request is being routed from the reverse
proxy to this application server.
So let's do one thing from the Nginx proxy IP ending with 90.
So this is the tab.
Let's do a control F5.
And if you see over here, the request actually came to this application server.
So this is the request that has come.
Now if you look into the IP address here, that is ten 139 0.3.
So this is basically a private IP address here.
Now we had also made a request just the moment before from our web browser, and this request basically
had a public IP.
So this is my current IP address of my ISP.
However, this new request that has come, this request has come from the private IP, which is nothing
but the IP address of this nginx reverse proxy server.
Now, in the idle environment, the client should not be able to directly communicate to the application
server only the nginx should be able to communicate to the application server.
However, for easy understanding, we explored both the connection of client to the application server
first and the client to the.
Techniques reverse proxy to the application server.
Now, along with this, the nginx reverse proxy server can also route the request based on the Uri of
that request.
For example, let's say that there are two servers now you have an application server and you have a
authentication server.
Authentication server is basically used to authenticate a client, maybe through Gmail, maybe through
username, password, etcetera.
So when a client makes a request, this request, if you will see is associated with login dot PHP.
So client wants to authenticate.
Now Nginx receives this request and what nginx does.
Nginx knows that whenever a authentication related request has come from the client, that request should
go to the authentication server.
And if you have a non authentication based request, that request should be sent to the application
server.
So you have great amount of flexibility related to the rules that you configure at a reverse proxy based
level.
So let's also look into it.
So let's do one thing.
This is the IP address of our reverse proxy server.
Now we also have a authentication server.
So this time when we make a request, something like admin index dot HTML, this time it is stating
that this is a auth server.
So basically Nginx determined that the client is trying to connect to a Uri of admin so it will go ahead
and route the request to the authentication server and not the application server.
Now let me also quickly show you.
So this is basically the authentication server.
Let's quickly do a tale on var log, Nginx access dot log.
All right, now let's go ahead and do a Ctrl F5 and this time you see a request was made to admin index.html
and this request was taken from a 10.1 39 .0.3, which is nothing but the IP address of a reverse proxy
based nginx server.
So this is basically the private IP address.
So to avoid the confusion, let me quickly show you if I quickly do a ifconfig in our nginx reverse
proxy server.
So you basically have a private IP address here which is ten 139 0.3 and also the public IP address
which is ending with 90.
So from the browser, we had made the request from this specific IP address and then Nginx through private
network, routed the traffic via ten 139 0.3 to the authentication server here.
Great.
So I hope with this you understood the basic concept of reverse proxy and also its associated architecture.
And with this we'll conclude today's video.