Nginx

Nginx is a web server used as a reverse proxy, load balancer, mail proxy, and HTTP cache, and follows a master-slave architecture

For the sake of simplicity, remember: Nginx is an amazing web server.

The web server, in simple terms, is like a middleman. For example, suppose you want to visit www.elephdev.com, so you enter the address https://www.elephdev.com, your browser will find out the address of the web server, https://www.elephdev.com and then Directed to the back-end server, the back-end server will return the response to the client

Proxy and reverse proxy

The underlying function of Nginx is a proxy. So now you need to understand what a proxy and a reverse proxy are

acting

Okay, so we have a client (>= 1), an intermediate web server (in this case, we call it a proxy), and a server. The main thing that happens in this case is that the server does not know which client is requesting

image.png

Here, let client1&client2 send request1&request2 to the server through the proxy server. Now the back-end server does not know whether request1 was sent by client1 or client2, but performs the operation

Reverse proxy

Simply put, reverse proxy and proxy have the opposite role. Here, we assume that there is a client, an intermediate web server, and several back-end servers (>=1)

image.png

In this case, the client will send the request through the web server. Now the web server will be directed to any one of the many servers through an algorithm, one is loop (the cutest!), and the response will be sent back to the client through the web server. So here, the client does not know which backend server it is interacting with

Load balancing

It is an example application of the reverse proxy itself

Let's take a look at the basic difference. In load balancing, you must have 2 or more backend servers, but in reverse proxy settings, this is not required. It can even be used with 1 backend server.

Let's take a look behind the scenes, if we have a lot of requests from clients, this load balancer will check the status of each backend server and distribute the load of the requests, and send responses to the clients faster

Stateful and Stateless Applications

Stateful application

This application stores an additional variable used to hold information that only applies to a single instance of the server

image.png

If the backend server server1 stores some information, it will not store some information for the server server2, so the client (here, Bob) interaction may/may not get the desired result because it may interact with server1 or server2. In this case, server1 will allow Bob to view the configuration file, but server2 will not. Therefore, even if it blocks many API calls to the database and is faster, it may cause this problem across different servers

Stateless application

Now, statelessness is more API calls to the database, but there are fewer problems in the interaction between the client and the different backend servers

image.png

I know you didn't understand what I meant. If I send a request from the client to the backend server server1 through the web server, it will provide the client with a token for access to any further requests, which is very simple. The client can use the token and send a request to the web server. The web server sends the request along with the token to any back-end server, and each back-end server will provide the same required output

What is Nginx?

Nginx is a web server, and until now I have used the term web server throughout my blog. Honestly, it’s like a middleman

image.png

The diagram is not confusing, it is just a combination of all the concepts I have explained so far. Here, we have 3 back-end servers running on ports 3001, 3002, and 3003, and all of these back-end servers use the same database running on port 5432.

Now, when the client sends a request GET /employees https://localhost (default port 443), it will pass this request to any backend server according to the algorithm, get the information from the database and send the JSON back to Nginx Web The server and send back to the client.

If we were to use an algorithm such as round-robin, what it would do is assume that client 2 has sent a request to it, https://localhost, then the Nginx server will first pass the request to port 3000 and send the response back to the client end. For another request, Nginx will pass the request to 3002, and so on.

The amount of information is too big! But so far, you have a clear understanding of what Nginx is and the terms used with Nginx. Now we will continue to understand installation and configuration techniques

Likes(0)

Comment list count 0 Comments

No Comments

WeChat Self-Service

WeChat Consult

TaoBao

support@elephdev.com

发表
评论
Go
Top