[Solved] Big File Size: Cannot upload file through Nginx Error 500
Reference: https://ofstack.com/Nginx/17070/nginx-upload-file-size-error-500-solution.html
TL:DR; Add `client_body_buffer_size 100M;` in nginx.conf, besides client_max_body_size, then restart nginx.
--
The symptoms are as follow:
- We have an Nginx server that routes traffic to internal Wordpress CMS
- When user uploads file through media page in WP, only file in small size (< 10K) can be uploaded, while file with large size (e.g. > 1M and <= 2M) cannot be uploaded.
- The error is: "Post-processing of the image failed likely because the server is busy or does not have enough resources. Uploading a smaller image may help. Suggested maximum size is 2500 pixels."
- Strictly speaking, this is a PHP image library error, not WP error. You cannot find this error in WP source code
- WP is hosted on Apache server.
- PHP post size, max size is setting to 80M (or any other large values) in php.ini.
- Nginx client client_max_body_size is set to 10M (or any other large value)
- No error logs
- WP did not create any error_log regarding this, as when big file is dragged to WP, it can't even "touch" WP and Nginx "immediately" produce 500 error
- Not "timeout", the 500 error is returned immediately
- No PHP error (since haven't touch WP at all), no wp-content/debug.log
- No Apache error (error_log, access_log)
- No Nginx log
- This is the most weird thing...
- Nginx error_log regarding the upload is completely "empty"
- No log related to upload
- Nginx access_log is also "empty"
- The error 500 is confirmed coming from Nginx!
Solution:
- Thanks to our colleague, the above reference shed a light on the actual, core problem.
- While we think that using `client_max_body_size` seems enough, it is not
- You need to also add `client_body_buffer_size` also, which is not defined by default in our nginx.conf
- Not sure if other version of Nginx has this config, in our case, we did not see that, even in conf.d/
- So our config include BOTH:
- `client_max_body_size 100M;` AND
- `client_body_buffer_size 100M;`
- After restarting Nginx, upload is fine again.
- We tested using a 5MB image and it is uploaded successfully.
Notes:
- We did not define client_body_temp_path in nginx.conf
- As long as everything works, keep it untouch/as it is
- Suppose both client_*_size is defined in nginx.conf under `server{}` section
- It is how I did.
- Lesson learnt: Actually we should be able to identify, if we think more deeply:
- Nginx returns error 500
- Nginx did not produce any error_log
- Given the above two points, the problem lies in "Nginx" and everything in front of Nginx (e.g. Firewall, load balancer)
- We have people checking on Firewall and load balancer, no trace, no log
- Since there is "No error", we should be able to identify that it is a config issue
- We believe and without checking that Nginx has already had all the configs, which is wrong
Hope it helps someone and save someone's lives ~~
Comments