Home > Article > Operation and Maintenance > What nginx mainly does
What does nginx mainly do?
Nginx is a high-performance HTTP and reverse proxy service, as well as an IMAP/POP3/SMTP service. Nginx was developed by the Russians.
Nginx is a lightweight web server/reverse proxy server and email (IMAP/POP3) proxy server, and is released under a BSD-like protocol. Its characteristics are that it occupies less memory and has strong concurrency capabilities. In fact, nginx’s concurrency capabilities do perform better among web servers of the same type. Most websites in mainland China use nginx.
1.1: Generally, websites using Nginx will mainly use
1. Reverse proxy
2. Load balancing
3. HTTP server (including dynamic Separation)
1.2 Reverse proxy
A picture tells you that it is not very clear and not easy to understand. Simply put, it is accepted by the proxy server. The connection request on the Internet is then forwarded to the server on the internal network, and the results obtained from the server are returned to the client requesting the connection on the Internet. At this time, the proxy server appears as a reverse proxy server to the outside world.
1.3 Load Balancing
The diagram can tell you simply, and then the algorithm used can also be shared with everyone
Polling (default): Each request is assigned to different back-end servers one by one in chronological order. If a back-end server goes down, the faulty machine will be automatically removed so that user access is not affected. I personally think this is the best , but there is also a cost, which is the cost of the machine! The actual situation has also verified this, the token of the mobile segment!
weight:
Specify the polling weight. The larger the weight value, the higher the probability of allocation. It is mainly used when the performance of each server in the backend is unbalanced. Personally, I don’t think this is necessary. Nowadays, the servers of most enterprises are on the cloud, and the configurations between machines are not much different. It doesn’t require a full-time job, and it’s not necessary!
ip_hash:
Each request is allocated according to the hash result of the access IP, so that each visitor has fixed access to a back-end server, which can effectively solve the session sharing problem of dynamic web pages. This is a common approach adopted in the PC era to solve the problem of session. As technology slowly evolves, session is no longer shared by netizens, and what follows is token, which solves the problem of user permission verification. This can only be used on small websites. The worst thing is that the access and traffic are all on a tomcat, so this approach is unlikely to be adopted!
1.3 HTTP server (including dynamic and static separation)
Nginx itself is also a static resource server. When there are only static resources, you can use Nginx as the server. At the same time, static resources are also very popular now. Separation can be achieved through Nginx. First, let's look at Nginx as a static resource server and separate some static resources. Each service does not need to be pulled from the network, and it is the fastest in terms of data.
1.4 Summary
Nginx has slowly acquired the heavyweight apache with light weight. It is now the mainstream, but it has been slowly replaced by others in recent years. Live until you are old, learn from the old, and embrace it. Variety!
The above is the detailed content of What nginx mainly does. For more information, please follow other related articles on the PHP Chinese website!