uwsgi_request_buffering

The 'uwsgi_request_buffering' directive controls whether request bodies are buffered while processing uWSGI requests.

Syntaxuwsgi_request_buffering on | off;
Defaulton
Contexthttp, server, location
Argumentsflag

Description

The 'uwsgi_request_buffering' directive in NGINX is critical for controlling how request bodies are handled when interfacing with uWSGI applications. When enabled, NGINX buffers the request body until the entire body is received, allowing the upstream server to access the complete payload at once. This can be particularly useful for handling large uploads or when the upstream server needs to validate the request body as a whole before processing it.

On the other hand, disabling request buffering can reduce memory usage and improve performance in scenarios of high concurrency or low request sizes, as NGINX will stream the request body directly to the uWSGI application without buffering it. The setting can be tuned depending on the expected request size and the performance characteristics of your application. The parameter for 'uwsgi_request_buffering' accepts a flag that can be either 'on' or 'off'. When set to 'on', buffering is enabled; when set to 'off', buffering is disabled.

It is important to understand the implications of this directive on your application's performance and choice of backend processing. In scenarios where real-time data is being streamed (e.g., file uploads) or responses need to be sent as soon as parts of the request are available, disabling buffering would be the preferred approach. Conversely, for complex payloads or where request integrity is critical, having this option enabled ensures that the request is analyzed in its entirety before processing.

Config Example

server {
    listen 80;
    server_name example.com;

    location / {
        uwsgi_pass 127.0.0.1:8000;
        uwsgi_request_buffering off;
    }
}

Using 'off' may lead to higher resource usage if large payloads are sent, as they will be streamed directly to the upstream without buffering.

If the upstream application cannot handle partial requests (i.e., expects the full request body), set it to 'on'.

← Back to all directives