Score:0

Force nginx to close the connection before receiving the whole body

kr flag

We have a upload system that is working behind a nginx reverse proxy, the system checks the authentication before starting to stream the request body from the client (passing through nginx) to the storage system, if the authentication failed, the backend doesn't stream the body but returns directly the HTTP 401 with a Connection: close header.

When testing authentication failure to the backend directly, as expected the connection is closed if the authentication failed and the payload is not uploaded, however when putting the backend behind nginx, I do see the backend sending back the 401 to nginx, but nginx wait for the whole request body to be received to send back the 401 (and the Connection: close) to the client (so potentially accepting multi gigabit files for nothing).

Is there a way to force nginx to stop receiving the body and directly respond to the client ? The current behaviour is an issue as it's wasting potentially a lot of bandwitdh and generating a lot of load on the nginx.

I tried to disable the keepalived but no luck

This is what I use for testing (httpie):

http --form --auth wrongtoken: POST http://localhost/upload [email protected]
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.