I am looking to limit the size of the client body
based on the content type in nginx.
location / {
if ($content_type = "application/json") {
client_max_body_size 1M;
client_body_buffer_size 512K;
}
...
...
}
I've tried the above if
condition which fails with below error.
nginx: [emerg] "client_max_body_size" directive is not allowed here
I have also tried using this without any effect
location ~* ^.+\.json {
client_max_body_size 1M;
client_body_buffer_size 512K;
}
You use a
map
directive in your http block but outside any server blocks.This sets the second variable based upon the value of the first, so by default it'll be 0 but if content type header is application/json it'll be 1M.
Now you use your custom variable like this
client_max_body_size $upload_limit;