0

Is there a way to tell Nginx to completely discard file uploads (or the entire POST body) for certain locations?

Say I have a location block like so:

server {
  listen [::]:80;
  listen 80;
  server_name foo.bor.com;

  return 200 '{"foo": "bar"';
}

It's as simple as it looks like - Nginx always responds with a dummy JSON.

However, if the request to that endpoint includes a larger (10MB) file, the response from Nginx is substantially delayed (up to 3sec). I am guessing that's because Nginx still parses/buffers the multipart content.

Is there a way to instruct Nginx to ignore POST body completely?

  • How long does it take to transmit 10MB to your server? – Richard Smith May 4 '19 at 6:47
0

You can restrict the allowed HTTP methods in that server block by testing the request_method embedded variable and returning a reasonable status code.

server {
    listen [::]:80;
    listen 80;
    server_name example.com;

    if ($request_method = POST ) {
        return 405;
    }

    return 200 '{"foo": "bar"}';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.