Squid, nginx, lighttpd reverse proxy difference

  
 

The reverse proxy can be divided into two types from the transmission:
1: synchronous mode (apache-mod_proxy and squid)
2: asynchronous mode (lighttpd and nginx)
in nginx In the introduction, the asynchronous transfer mode is mentioned and it can reduce the number of backend connections and pressure. Why?
The following explains the difference between the traditional proxy (apache/squid) synchronous transfer and lighttpd, nginx asynchronous transfer:
squid, nginx, lighttpd reverse proxy
synchronous transfer: browser initiates request Then the request is immediately transferred to the background, so a channel is established between the browser and the background. This channel is always present until the request is initiated until the request is completed. Asynchronous transfer: The browser initiates the request, the request does not immediately go to the background, but the request data (header) is first received on nginx, then nginx sends the request to the backend, and the data is returned to the backend after processing. On nginx, nginx sends the data stream to the browser. This is a bit different from lighttpd, which is sent to the browser after the backend data is completely received.
Summary: The reverse of apache and squid will increase the burden of the back-end web, because each user request will be a long-term link with the back-end server on the proxy, knowing that the connection will not disappear until the data is taken. Because the wan speed is different from the lan speed, although the speed between lan is extremely fast, the user's wan connection determines this time. The light mode of lighttpd and nginx is that no matter how big the data your users require, it is first received and then connected with the backend. This is very fast, so the connection time between the proxy and the backend will be very short. Ten M's things are also within a few seconds. The backend does not need to maintain so many connections. The lighttpd is also asynchronous to nginx. The lighttpd is sent to the client browser first, and nginx is turned to the user's browser while collecting data.


then that in the end what good is it?
1. Suppose the user performs an upload file operation because the user's network speed is slower, so it takes half an hour to transfer the file to the server. Squid's synchronization agent establishes a connection with the background after the user starts uploading. After half an hour, the file upload ends. It can be seen that the background server connection is kept for half an hour; and the nginx asynchronous proxy first receives this file on nginx. Therefore, only nginx and the user keep the connection for half an hour. The background server does not open the connection for this request within half an hour. After half an hour, the user upload ends, and nginx sends the uploaded content to the background. The bandwidth between nginx and the background is Very plentiful, so it took only a second to send the request to the background, which shows that the background server connection stayed for one second. Synchronous transfer took a background server for half an hour, and asynchronous transfer took only one second, which shows that the optimization is very large.
2. In the above example, if the background server is restarted for various reasons, the upload file is naturally interrupted. This is very annoying to the user. Presumably, everyone has uploaded the file and half of it is interrupted. Experience. After using nginx proxy, the impact of the background server restart on user upload is reduced to the extreme, and nginx is very stable and does not need to be restarted frequently. Even if you need to restart, you can use hail-HUP to restart nginx without interruption.
3. Asynchronous transfer can make the load balancer more secure. Why do you say that? In other equalizers (lvs/haproxy/apache, etc.), each request has only one chance. If the user initiates a request and the backend server that the request is assigned to just hangs, the request fails. And because nginx is asynchronous, this request can be sent back to the next background, the next background returns normal data, so the request can be successful. Still use the example of user uploading files. If you not only use nginx proxy, but also use load balancing, nginx sends the uploaded file to one of the backgrounds, but this server suddenly restarts. After receiving the error, nginx will upload this. The file is sent to another background, so the user does not have to spend another half an hour to upload it.
4. If the user uploads a 10GB file and the background server does not take this into account, then the background server should not crash. With nginx you can put these things on nginx, limit the function size limit of nginx upload file, and the performance of nginx is very secure, so rest assured that the other users on the Internet and nginx fight against it.
Asynchronous transfer will cause problems:
The background server has the function of providing upload progress. If you use the nginx agent, you can't get progress. This needs to be implemented by a third-party module of nginx.

Copyright © Windows knowledge All Rights Reserved