To address and resolve the issue where image uploads to an application via NGINX reverse proxy result in the error:
"413 Request Entity Too Large"
This error typically occurs when the size of the request body (e.g., an uploaded file or image) exceeds the limits configured in NGINX or the backend server.
1. NGINX Configuration
Ensure the following directives are included within the appropriate server or location block in your NGINX configuration file:
location / {
proxy_pass http://localhost:9002;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffer_size 128k; # Buffer size for response headers
proxy_buffers 4 256k; # Number and size of buffers
proxy_busy_buffers_size 256k; # Busy buffer size
client_max_body_size 10m; # Maximum client request body size
}
Explanation of Options:
proxy_pass: Forwards requests to the backend server.
proxy_set_header: Ensures original headers and IPs are passed to the backend.
proxy_buffer_size: Avoids header overflow.
proxy_buffers: Defines the number and size of temporary buffers for the response body.
proxy_busy_buffers_size: Used during data streaming to the client.
client_max_body_size: Sets max upload size allowed by NGINX.
Note: client_max_body_size must be placed inside server {} or location {} block—not just globally.
2. Restart/Reload NGINX
Validate and apply the changes:
sudo nginx -t
sudo systemctl reload nginx
Verification
Upload an image smaller than 10MB.
Confirm that the upload is successful without encountering HTTP 413 errors.
By setting client_max_body_size and aligning buffer limits with the backend application limits, the issue of image uploads failing due to size constraints in NGINX can be effectively resolved.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our DevOps Expertise.
Contact Us