$proxy_internal_chunked

$proxy_internal_chunked indicates whether internal responses should be sent in chunked transfer encoding. — NGINX Core (HTTP)

$proxy_internal_chunked NGINX Core (HTTP)

Description

The variable $proxy_internal_chunked controls the transfer encoding method utilized by NGINX for internal responses forwarded by the proxy module. When set to "on", it signifies that responses without a predefined Content-Length should be transmitted using chunked transfer encoding, enabling the streaming of data to clients as it becomes available. This is particularly useful for dynamic content, where the length of the response is not known in advance. This variable is typically set in location blocks or server contexts, primarily during proxying when a client request is handled by a backend server. The default behavior of NGINX uses chunked encoding if the upstream server does not specify a Content-Length header, which allows clients to begin processing the response immediately without waiting for the entire body to be sent. Developers can selectively enable or disable this feature based on their specific use cases and the behavior of the upstream services they are connecting to, making it a flexible option in managing how data is served. In practice, proxy_internal_chunked may result in performance benefits when dealing with large or streaming responses, but it can introduce complexity for clients that may not handle chunked responses correctly. Therefore, careful consideration of client compatibility and performance implications should be observed when configuring NGINX to use this variable.

Config Example

location /api {
    proxy_pass http://backend;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_buffering off;
    # Enable chunked transfer for internal responses
    set $proxy_internal_chunked on;
}

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

Ensure that upstream servers can handle chunked transfer encoding properly, as some older clients may not support it.

Disabling buffering with 'proxy_buffering off;' may result in unexpected performance issues if the upstream is slow.

Remember that chunked responses can complicate content delivery over HTTP/1.0 and may not work with certain proxies or intermediaries.