proxy_force_ranges

The proxy_force_ranges directive allows NGINX to serve partial content requests through a proxy by forcing the proxy to handle range requests. — NGINX HTTP Core

proxy_force_ranges
httpserverlocation
Синтаксисproxy_force_ranges on | off;
По умолчаниюoff
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументыflag

Описание

The `proxy_force_ranges` directive, when set to `on`, instructs NGINX to enable range requests with proxied content. This directive is particularly important when the upstream server does not support range requests, as it ensures that partial content can still be served correctly by allowing NGINX to manipulate the range headers as needed. This effectively allows clients to request specific portions of a resource, reducing bandwidth usage and improving responsiveness for large files, such as videos or archives. When the directive is enabled, NGINX takes full control over the Range requests from clients, forwarding the required ranges to the upstream server. If the upstream server does not support range requests, NGINX will perform the necessary segmentation of the data received and deliver it to the client as if it had support for ranges, thus ensuring seamless operation even when the upstream service is limited in its capabilities. This enhances client experience, especially in scenarios involving large data sets or media files. It should be noted that the use of this directive can slightly affect performance since additional processing is needed to handle the range requests, particularly when the full content is being proxied and the upstream does not handle range requests directly. Furthermore, enabling this directive can increase complexity in response handling as NGINX has to carefully manage the byte ranges specified by clients and the responses received from upstream servers.

Пример конфига

location /files {
    proxy_pass http://backend;
    proxy_force_ranges on;
}

Ensure that the upstream server cannot handle range requests, otherwise it may lead to unintended behavior.

When enabled, this directive requires appropriate testing to ensure that performance does not degrade unexpectedly due to NGINX's overhead in managing the ranges.