Reverse Proxy and load balancing
One, the traditional agent (APACHE/SQUID) of synchronous transmission and nginx asynchronous transmission of the difference.
Second, synchronous transmission and asynchronous transmission comparison
Squid synchronous Transmission: The browser initiates the request and the request is immediately transferred to the background, thus creating a channel between the browser and the background. The channel is always present until the request has been initiated.
Nginx Asynchronous Transmission: The browser initiates a request, the request does not immediately go to the background, but the request data (header) first receives the Nginx, then Nginx then sends the request to the back end, after processing the back end to return the data to the Nginx, Nginx sends the data stream to the browser, This is a bit different from the LIGHTTPD, LIGHTTPD is to send back-end data to the browser when it is fully received.
So what's the benefit?
1 If the user performs an upload file operation, because the user speed is slower, it takes half an hour to upload the file to the server. Squid synchronization agent after the user began to upload and backstage to establish a connection, half an hour after the file upload end, this shows that the backend server connection has been maintained for half an hour, occupy the system resources; Nginx Asynchronous agent is the first to receive this file Nginx, so just nginx and users Kept the connection for half an hour, background server in this half hour did not open the connection for this request, half an hour after the user upload end, Nginx will upload content to the background, nginx and the background between the bandwidth is very abundant, so only spent a second to send the request to the backstage, thus, The backend server connection remained for one second. Synchronous transmission spent half an hour in the background server, asynchronous transmission only a second, visible optimization degree is very large.
2 in the above example, if the background server for a variety of reasons to restart, the upload file will naturally be interrupted, which is very annoying to the user is a thing, presumably you have uploaded files to half interrupted experience. With the Nginx agent, the backend server restart on the user upload effect reduced to the extreme, and Nginx is very stable does not need to restart it often, even if the need to restart, the use of kill-hup can be achieved uninterrupted restart Nginx.
3 asynchronous transmission can make the load balancer more secure, why do you say so? In other equalizer (Lvs/haproxy/apache, etc.), each request is only one chance, if the user initiates a request, the result of the request to the backend server just hung up, then the request failed; and Nginx because it's asynchronous, So this request can be sent back to the next background, the next background returned the normal data, so the request can be successful. Or with the user upload file This example, if not only use the Nginx agent, and use the load balance, nginx upload file to one of the backstage, but this server suddenly restarted, Nginx received the error, will upload the file to another background, So users don't have to spend half an hour uploading.
4 If the user uploads a file of 10GB size, the latter server did not consider this situation, then the background server will not crash. With Nginx can put these things on the Nginx, through the Nginx upload file size limit function to limit, in addition to nginx performance is very secure, it is safe to let the Internet on those alternative users and nginx confrontation go.
Using asynchronous transmissions can cause problems:
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/
Background server has the ability to provide upload progress, using the Nginx agent can not achieve progress, this need to use a Nginx third-party module to achieve.
Three, Nginx set asynchronous agent
Set the following parameters in the HTTP domain
Parameter description