chunked_transfer_encoding
The 'chunked_transfer_encoding' directive enables or disables chunked transfer encoding for HTTP responses in NGINX.
Description
When the chunked_transfer_encoding directive is set to 'on', NGINX will use chunked transfer encoding to send responses to clients, instead of specifying the total content length in the HTTP headers. Chunked transfer encoding is particularly useful for dynamically generated content, where the total size of the content is not known at the start of the response. By using this method, NGINX can start sending data to the client as soon as it is available, which can improve the perceived performance of the application and reduce latency.
The directive accepts a flag argument, which can be 'on' or 'off'. When set to 'on', NGINX will enable chunked transfer encoding, while 'off' will disable it. The positioning of this directive is flexible; it can be used in the http, server, or location contexts, allowing the user to apply it broadly or in a specific context according to their needs. Typically, it is more beneficial to enable chunked transfer encoding for responses that are generated dynamically, such as those created by CGI scripts or reverse proxying to an application server, where the final content length is not known in advance.
Config Example
http {
server {
location / {
chunked_transfer_encoding on;
proxy_pass http://backend;
}
}
}Disabling chunked transfer encoding when using dynamic content may lead to increased latency, since NGINX will need to know the total content length before sending the response.
Mixing chunked responses with buffer settings may cause unexpected behavior; ensure buffer configurations are compatible with chunked encoding when enabled.