How NginxProxybuffer works

Source: Internet
Author: User
There has been no authoritative explanation of proxybuffer principles on the Internet, and most of them are their own guesses. This time, I spent more than a day carefully reading the relevant nginx source code, and I also made a forum on Nginx, after fully understanding the problem, writing this article can be said to be the most authoritative Chinese interpretation that can be found on the Internet. First, the concept of buffer is

There has been no authoritative explanation of the proxy buffer principle on the Internet, and most of them are their own guesses. This time, I spent more than a day carefully reading the relevant nginx source code, and I also made a forum on Nginx, after fully understanding the problem, writing this article can be said to be the most authoritative Chinese interpretation that can be found on the Internet. First, the concept of buffer is

There has been no authoritative explanation of the proxy buffer principle on the Internet, and most of them are their own guesses. This time, I spent more than a day carefully reading the relevant nginx source code, and I also made a forum on Nginx, after fully understanding the problem, writing this article can be said to be the most authoritative Chinese interpretation that can be found on the Internet. The first concept of buffer is that all these proxy buffer parameters work for each request. Each request will obtain its own buffer according to the parameter configuration. Proxy buffer is not global but per request.

Proxy_buffering is used to enable response buffering of the proxied server. After this is enabled, the proxy_buffers and proxy_busy_buffers_size parameters will take effect.

Whether proxy_buffering is enabled or not, proxy_buffer_size (main buffer) works. The buffer_size set by proxy_buffer_size is used to store the response header of upstream.

When proxy_buffering is enabled, Nginx will try to read all the data transmitted by upstream to the buffer, until all the buffers set by proxy_buffers are fully written or the data is read (EOF ). At this time, nginx starts to transmit data to the client, and the entire buffer string will be transmitted at the same time. At the same time, if the response content is large, Nginx will receive and write them into temp_file. The size is controlled by proxy_max_temp_file_size. If the buffer of busy is transmitted, the data will be read from temp_file until the transmission is complete.

Once the buffer set by proxy_buffers is written, the buffer will remain in the busy State until the data in the buffer is completely transmitted (transmitted to the client, we cannot perform any other operations on these buffers. All buffer sizes in the busy state cannot exceed proxy_busy_buffers_size. Therefore, proxy_busy_buffers_size is used to control the number of buffers simultaneously transmitted to the client.

The following is a supplement to these parameters:

Related parameter proxy_buffer_sizeSyntax: proxy_buffer_size the_size

Default Value: proxy_buffer_size 4 k/8 k

Context: http, server, location

This command sets the buffer size. The first part of the response content obtained from the proxy backend server will be placed here.

A small response header is usually located in this part of the response content.

By default, the buffer size is equal to the value set by proxy_buffers. However, you can set it to a smaller value. proxy_bufferingSyntax: proxy_buffering on | off

Default Value: proxy_buffering on

Context: http, server, location

This command enables response content buffering from the back-end proxy server.

If the buffer zone is enabled, nginx assumes that the backend server to be proxy will respond as quickly as possible and save the content in the buffer zone specified by the instruction proxy_buffer_size and proxy_buffers.

If the response content cannot be stored in the memory, some content will be written to the disk.

If the buffer zone is disabled, the response content is immediately transmitted to the client based on the amount of content obtained.

Nginx does not try to calculate the total response content size of the proxy server. The maximum data that nginx can receive from the server is specified by the proxy_buffer_size command.

For long-polling (long-polling)-based Comet applications, disabling proxy_buffering is important. Otherwise, asynchronous responses will be cached and Comet cannot work proxy_buffers.Syntax: proxy_buffers the_number is_size;

Default Value: proxy_buffers 8 4 k/8 k;

Context: http, server, location

This command sets the buffer size and quantity. The response content obtained from the proxy's backend server will be placed here. by default, the size of a buffer is equal to the size of the Memory Page, which may be 4 K or 8 K, depending on the platform. Proxy_busy_buffers_sizeSyntax: proxy_busy_buffers_size size;

Default Value: proxy_busy_buffers_size proxy_buffer_size * 2;

Context: http, server, location, if

TODO: Description.

Original article address: Working Principle of Nginx Proxy buffer. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.