nginx error encyclopedia: 502, 504, 413, 403 and more
Causes, commands and fixes for common nginx errors: 502, 504, 499, 413, 403, 404, 405, cookie too large, PHP File not found, redirect loops, SSL, port in use.
502Nginx 502 Bad Gateway: causes and fixes
502 means nginx could not reach or understand the backend (PHP-FPM, Node, a Docker contain… 504Nginx 504 Gateway Timeout: causes and fixes
504 means the backend did not answer within nginx's timeout. Find what is slow first (quer… 413Nginx 413 Request Entity Too Large: upload size fix
413 means the request body exceeded client_max_body_size (default only 1 MB). Raise it in … 403Nginx 403 Forbidden: causes and fixes
403 usually means no index file in a directory, file permissions nginx cannot read, a deny… 404Nginx 404 and try_files: rewrites, SPA routes, root vs alias
404 although the file exists is usually a wrong root/alias path, or WordPress / Vue / Reac… 3xxERR_TOO_MANY_REDIRECTS with nginx: how to fix
“Too many redirects” is most often a CDN fetching your origin over HTTP while the origin r… SSLNginx SSL handshake failed: troubleshooting
SSL handshake failures usually come from a cert without the full chain, a cert/key mismatc… bindnginx: bind() failed (98: Address already in use)
Port 80/443 is already taken (Apache, Caddy, a panel, a Docker container, another nginx), … EOFupstream prematurely closed connection: causes and fixes
The backend closed the connection before nginx got the full response. Typical causes: back… 13nginx (13: Permission denied): troubleshooting
13: Permission denied appears when reading files, connecting to a socket, writing logs or … 400Nginx 400 Request Header Or Cookie Too Large: fix
400 “Request Header Or Cookie Too Large” means one request header line, usually Cookie, is… 499Nginx 499 Client Closed Request: what it means
499 is an nginx-specific code that only appears in access logs: the client closed the conn… 500Nginx 500: rewrite or internal redirection cycle
“rewrite or internal redirection cycle” means the request was redirected internally more t… 404nginx + PHP-FPM “File not found” / Primary script unknown
A bare “File not found.” page with “Primary script unknown” in the log means PHP-FPM could… 502Nginx 502: upstream sent too big header
“upstream sent too big header” means the backend's response headers (usually many or large… 502nginx: no resolver defined to resolve — causes and fix
When proxy_pass contains a variable (proxy_pass https://$host, $backend…), the name is res… emergcould not build server_names_hash: how to fix
nginx -t failing with “could not build server_names_hash, you should increase server_names… warnnginx warning: conflicting server name … ignored
“conflicting server name "example.com" on 0.0.0.0:80, ignored” means two server blocks on … 405Nginx 405 Not Allowed: why POST is rejected
nginx answering 405 Not Allowed usually means a POST (or PUT, DELETE) request ended up on … emergnginx unknown directive: http2, brotli, quic and more
nginx -t reporting “unknown directive "http2"” and the like means this nginx does not know… emergnginx cannot load certificate: missing file or key mismatch
nginx -t reporting “cannot load certificate … No such file or directory” most often means …
502 means nginx could not reach or understand the backend (PHP-FPM, Node, a Docker contain… 504Nginx 504 Gateway Timeout: causes and fixes
504 means the backend did not answer within nginx's timeout. Find what is slow first (quer… 413Nginx 413 Request Entity Too Large: upload size fix
413 means the request body exceeded client_max_body_size (default only 1 MB). Raise it in … 403Nginx 403 Forbidden: causes and fixes
403 usually means no index file in a directory, file permissions nginx cannot read, a deny… 404Nginx 404 and try_files: rewrites, SPA routes, root vs alias
404 although the file exists is usually a wrong root/alias path, or WordPress / Vue / Reac… 3xxERR_TOO_MANY_REDIRECTS with nginx: how to fix
“Too many redirects” is most often a CDN fetching your origin over HTTP while the origin r… SSLNginx SSL handshake failed: troubleshooting
SSL handshake failures usually come from a cert without the full chain, a cert/key mismatc… bindnginx: bind() failed (98: Address already in use)
Port 80/443 is already taken (Apache, Caddy, a panel, a Docker container, another nginx), … EOFupstream prematurely closed connection: causes and fixes
The backend closed the connection before nginx got the full response. Typical causes: back… 13nginx (13: Permission denied): troubleshooting
13: Permission denied appears when reading files, connecting to a socket, writing logs or … 400Nginx 400 Request Header Or Cookie Too Large: fix
400 “Request Header Or Cookie Too Large” means one request header line, usually Cookie, is… 499Nginx 499 Client Closed Request: what it means
499 is an nginx-specific code that only appears in access logs: the client closed the conn… 500Nginx 500: rewrite or internal redirection cycle
“rewrite or internal redirection cycle” means the request was redirected internally more t… 404nginx + PHP-FPM “File not found” / Primary script unknown
A bare “File not found.” page with “Primary script unknown” in the log means PHP-FPM could… 502Nginx 502: upstream sent too big header
“upstream sent too big header” means the backend's response headers (usually many or large… 502nginx: no resolver defined to resolve — causes and fix
When proxy_pass contains a variable (proxy_pass https://$host, $backend…), the name is res… emergcould not build server_names_hash: how to fix
nginx -t failing with “could not build server_names_hash, you should increase server_names… warnnginx warning: conflicting server name … ignored
“conflicting server name "example.com" on 0.0.0.0:80, ignored” means two server blocks on … 405Nginx 405 Not Allowed: why POST is rejected
nginx answering 405 Not Allowed usually means a POST (or PUT, DELETE) request ended up on … emergnginx unknown directive: http2, brotli, quic and more
nginx -t reporting “unknown directive "http2"” and the like means this nginx does not know… emergnginx cannot load certificate: missing file or key mismatch
nginx -t reporting “cannot load certificate … No such file or directory” most often means …
One-command check on the server: curl -fsSL nginx.cc/fix | sudo bash