How to Fix 'Client Intended to Send Too Large Body' Nginx 413 Error

Updated
featured-image.png

This can happen when a user upload a very large sized file to our app that served with Nginx. Maybe the user see the following error

nginx-413.jpeg

And when we search for an error log for this in Nginx error log in - for example - for CentOS it is located at /var/log/nginx/error.log, we found Client Intended to Send Too Large Body: xxxxxx bytes error.

Let’s fix this by adding a rule in our Nginx config file. We need to add client_max_body_size rule.

Setting for Spesific Site Only

If you want this rule for spesific site only, set this inside your spesific site config that located at /etc/nginx/sites-available/mywebsite.com.conf

For example We can use nano to open the config file

sudo nano /etc/nginx/sites-available/mywebsite.com.conf

Then insert the following rule

server {
    ...
    # set the maximum upload to 20MB
    client_max_body_size 20M;
    ...
}

Setting for All Server Blocks

If we want the rule to affects all server blocks, set it inside /etc/nginx/nginx.conf.

http {
    ...
    # set the maximum upload to 20MB
    client_max_body_size 20M;
    ...
}

Note: Setting size to 0 disables checking of client request body size.

Check Nginx Configuration And Restart

Next, check our configuration by running

sudo nginx -t

If it says “syntax is ok” then we are ready to restart our Nginx.

sudo systemctl restart nginx

Conclusion

That’s it, our app should be able to receive files with size under 20MB with this client_max_body_size rule in Nginx.

Read Also

Reference

How to Limit File Upload Size in Nginx

Fajarwz's photo Fajar Windhu Zulfikar

I'm a full-stack web developer who loves to share my software engineering journey and build software solutions to help businesses succeed.

Email me
Ads
  • Full-Stack Laravel: Forum Web App (Complete Guide 2024)
  • Flexible and powerful review system for Laravel, let any model review and be reviewed.

Share

Subscribe

Sign up for my email newsletter and never miss a beat in the world of web development. Stay up-to-date on the latest trends, techniques, and tools. Don't miss out on valuable insights. Subscribe now!

Comments

comments powered by Disqus