What is Nginx?

Nginx is a web server that can also be used as a

  • reverse proxy
  • load balancer
  • HTTP cache

Nginx is known for its high concurrency, high performance and low memory usage compared to Apache.

Reverse Proxy

Nginx can be used as a reverse proxy to hide the real IP address of the application server. The benefit of using a reverse proxy is that the client does not need to know the real location of the application server, and only needs to send requests to the application server through the Nginx reverse proxy. The application server also does not need to know which client's request, just need to return the response.

Nginx Reverse Proxy
Nginx Reverse Proxy

Load Balance

To handle high-volume traffic, one application server is not enough, so multiple application servers are needed at the same time. Nginx can automatically distribute the Client's Request to different application servers, and the distribution algorithm can be designed by yourself. The most common algorithm is Round Robin, and other algorithms include Least Connections, Least Time, IP Hash, etc.

Nginx Load Balance
Nginx Load Balance

HTTP Cache

To improve performance, Nginx will optimize by using the HTTP cache mechanism. The process is as follows:

  1. Client sends a request, Nginx will hash the request information and determine whether the hash key exists in the memory: ① → ②
    1. If the hash key does not exist in the memory: Nginx will ask the application server for the file location, and then ask for the file. ③ → ④ → ⑤
    2. If it exists in the memory: Nginx will directly ask for the file. ③ → ⑤
  2. Return the file to the client
Nginx Cache
Nginx Cache