How do I fix Nginx 'upstream sent too big header' 502 error?
Increase `proxy_buffer_size 16k;` and `proxy_buffers 4 32k;` (or `fastcgi_buffer_size` for PHP-FPM) inside your `location` block and reload Nginx.
HTTP 502 Bad Gateway means a reverse proxy (Nginx, Cloudflare, AWS ALB) could not get a valid HTTP response from the upstream application server—usually because the app crashed, closed the socket, or sent headers larger than `proxy_buffer_size`.
upstream app_backend {
server 127.0.0.1:3000 max_fails=3 fail_timeout=10s;
keepalive 32;
}
server {
location / {
proxy_pass http://app_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 32k;
}
}
curl -i -sS http://127.0.0.1:3000/health && tail -n 30 /var/log/nginx/error.log
Increase `proxy_buffer_size 16k;` and `proxy_buffers 4 32k;` (or `fastcgi_buffer_size` for PHP-FPM) inside your `location` block and reload Nginx.
Check the `Server` header and error page branding. A Cloudflare 502 page shows a Cloudflare Ray ID; an Nginx 502 shows `nginx` in the plain HTML footer.
Old containers are terminated before the load balancer drains active connections. Implement graceful shutdown (`SIGTERM` handler) and health-check drain delays.