Nginx 413 Error – Why It Might Not Flush to Client Immediately

httpnginx

I have my local development server returning status 413 for oversized file uploads and the client is receiving these immediately – as I require.

My remote server is the same version of Nginx and more-or-less the same configuration, but the 413 never reaches the browser.

An error indicating the data is oversized appears in the error log straight away and nothing appears in the access log. The browser continues to send the data and after 30 seconds the 413 status appears in the access log (and again in the error log) and the browser times out with an internal 'connection reset' error.

What configurations on the remote server could cause this delay?

Best Answer

The problem is that most HTTP clients don't read the response until they've sent the entire request body. If you're dealing with webbrowsers you're probably out of luck here. The only server side configuration you can do is set keepalive_requests to 0 (which disables persistent connections), which might make nginx close the connection after sending the 413 which should cause the client to stop sending the data. The client is likely to report a network error instead of 413 however.