sendfile() failed (9: Bad file descriptor) while sending request to upstream

papajoe nginx-forum на
Чт Фев 22 13:12:25 UTC 2018

Hey everybody,

I experienced this issue using nginx version 1.10.x and 1.13.x

given a basic configuration like:

upstream myupstream {
    server internal01:80;
    server internal02:80 backup;

server {
    listen 81 default_server;
    listen [::]:81 default_server;

    server_name _;

    location / {
        proxy_pass http://myupstream;
        post_action @hot_standby;

    location @hot_standby {
        proxy_pass http://internal02:80;

I receive the "sendfile() failed (9: Bad file descriptor) while sending
request to upstream"  error when trying to POST data exceeding 16k body
size. The error does not occur for requests with less than 16k data.
As far as I can understand the code / documentation, 16k by default (for
64bit systems) is the limit when nginx starts to use a tempfile instead of a
memory buffer.

This makes me believe that the problem only kicks in when nginx decides to
use a tempfile instead of an inmemory buffer.

For my setup I was able to fix the issue by an alignment between
client_body_buffer_size and client_max_body_size.

client_max_body_size    1m;
client_body_buffer_size   1m;

Hope this can help anybody.


Posted at Nginx Forum:,118976,278721#msg-278721

Подробная информация о списке рассылки nginx-ru