@kyanny's blog

My thoughts, my life. Views/opinions are my own.

How to check nginx client_max_body_size default size 1MB

http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

Run a nginx docker container.

docker run -it --rm -p 8080:80 nginx

Create a binary file.

dd if=/dev/urandom of=1M.data bs=1024 count=1024
cp 1M.data 1M+1.data
echo -n 0 >> 1M+1.data

Send a request.

  • Be sure using --data-binary instead of -d (--data)

Nginx accepts 1MB data. (It returns 405 Not Allowed for the different reason, but doesn't return 413 Request Entity Too Large)

curl -v --data-binary @1M.data localhost:8080
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 1048576
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 405 Not Allowed
< Server: nginx/1.21.3
< Date: Fri, 22 Oct 2021 08:56:47 GMT
< Content-Type: text/html
< Content-Length: 157
< Connection: keep-alive
* HTTP error before end of send, stop sending
<
<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.21.3</center>
</body>
</html>
* Closing connection 0

Nginx rejects 1MB + 1byte data.

curl -v --data-binary @1M+1.data localhost:8080
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 1048577
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 413 Request Entity Too Large
< Server: nginx/1.21.3
< Date: Fri, 22 Oct 2021 08:56:53 GMT
< Content-Type: text/html
< Content-Length: 183
< Connection: close
<
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.21.3</center>
</body>
</html>
* Closing connection 0

Special thanks to

kdnakt.hatenablog.com