Tips27 Aug 2026Joy Team2 min read

Nginx 911: how to fix 502 Bad Gateway & 413 Entity Too Large errors

Getting a 502 Bad Gateway or 413 Upload Error on your VPS? Here are the command-line fixes to get your Nginx server back online in minutes.

502 Bad Gateway

Nginx received the request but the upstream (PHP-FPM, Node, Gunicorn) did not answer. Find out which:

tail -n 50 /var/log/nginx/error.log
systemctl status php8.3-fpm     # or your app service

Fix 1 — the upstream is down

systemctl restart php8.3-fpm    # or: systemctl restart myapp

If it keeps dying, check memory (dmesg | grep -i kill) and add swap.

Fix 2 — wrong socket path

The error log says connect() to unix:/run/php/php8.2-fpm.sock failed but you run 8.3. Match fastcgi_pass in your server block to the socket that exists in /run/php/, then nginx -t && systemctl reload nginx.

Fix 3 — timeouts on slow requests

location ~ \.php$ {
    fastcgi_read_timeout 300;
    proxy_read_timeout 300;   # for proxied apps
}

413 Request Entity Too Large

An upload exceeded Nginx's default 1 MB body limit. Raise it in the server block (or http block for all sites):

client_max_body_size 64M;

For PHP also raise upload_max_filesize and post_max_size in /etc/php/8.3/fpm/php.ini, then:

nginx -t && systemctl reload nginx && systemctl restart php8.3-fpm

Prevent the next one

Put the Joy CDN in front of the site so bursts are absorbed at the edge, keep a snapshot before config changes, and add a simple uptime check against /healthz that restarts the app service when it fails.

nginxphptroubleshooting
Was this article helpful?
Corrections and suggestions go straight to the team that wrote it.