If you have an Nginx server set up to handle file uploads, and a user tries to upload a file that is larger than the configured client_max_body_size
directive. When this happens, Nginx logs an error message that looks something like this:
[error] 1234#0: *56789 client intended to send too large body: 123456789 bytes
Let’s resolve it.
Prerequisites
- nginx
- sudo privileges
Solution
According to the log mentioned above, the client sent a request with a body size of
123MB
, where it’s likely that nginxclient_max_body_size
directive has a lower value. To resolve this, we need to increase the value ofclient_max_body_size
to be greater than 123MB.- You can adjust the value of the
client_max_body_size
directive in your Nginx configuration to allow for larger request bodies to be accepted. For example, you can increase the value to 200MB:server { listen 80; server_name example.com; # Set the maximum allowed size of the client request body to 200M client_max_body_size 200M; location / { proxy_pass http://upstream_server; } }
- Remember to reload the Nginx configuration for the changes to take effect:
sudo systemctl reload nginx
Conclusion
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.