Server errors: error fixes

Messages from PHP, MySQL, nginx and Apache logs: what they mean, why they happen and the exact setting to change.

Error fix · Server errors502 Bad Gateway: Is It the CDN or Your Origin? How to TellWork out whether a 502 Bad Gateway comes from your CDN, a load balancer or your origin server, using response headers, error pages and direct origin tests.5 min readError fix · Server errors504 Gateway Timeout by Layer: nginx, Load Balancer, CDN and App TimeoutsA 504 depends on which timer fired first. See default timeouts and settings for nginx, Apache, AWS load balancers, Cloudflare, gunicorn and PHP-FPM.5 min readError fix · Server errorsApache .htaccess 500 Internal Server Error: Find the Bad LineA broken .htaccess file makes Apache return 500 for the whole site. Read the error log, find the bad directive, and fix syntax, modules or AllowOverride.4 min readError fix · Server errorsApache "(98)Address already in use: could not bind to addressApache fails to start with AH00072 make_sock could not bind to address. Find the process holding port 80 or 443, or the duplicate Listen line, and fix it.4 min readError fix · Server errorsApache "client denied by server configuration" (AH01630) FixFix Apache 403 errors logged as "AH01630: client denied by server configuration" by replacing old Order/Allow rules with Require and checking Directory blocks.4 min readError fix · Server errorsApache "Forbidden: You don't have permission to access this resourceApache 403 Forbidden on a new site is usually file permissions, a missing index file, SELinux or a Require rule. Use the error log to pick the right fix quickly.4 min readError fix · Server errorsApache "Invalid command" in .htaccess: Enable the Missing ModuleFix Apache's "Invalid command perhaps misspelled or defined by a module not included" error by enabling the right module, wrapping rules in IfModule, or removing the line.4 min readError fix · Server errorsApache "Premature end of script headers": Causes and FixesApache logs "Premature end of script headers" when a CGI, PHP-CGI or FastCGI script exits before sending valid headers. Check the script, shebang, permissions and limits.4 min readError fix · Server errorsApache mod_rewrite Not Working: Rules Ignored or 404? Fix ItWhen RewriteRule seems to do nothing in Apache, check that mod_rewrite is enabled, AllowOverride permits .htaccess, and the rule matches. Includes debug logging.4 min readError fix · Server errorsHTTP 400 Bad Request: What It Means and How to Fix ItFix HTTP 400 Bad Request as a visitor (cookies, URL, cache) or as a site owner (malformed headers, oversized cookies, proxy and app validation rules).4 min readError fix · Server errorsHTTP 403 Forbidden: Why It Happens and How to Fix ItFix HTTP 403 Forbidden as a visitor or owner: file permissions, missing index, nginx and Apache access rules, WAF and CDN blocks, hotlink and IP restrictions.4 min readError fix · Server errorsHTTP 404 Not Found: Find the Cause and Fix Broken URLsFix HTTP 404 Not Found as a visitor or owner: typos, moved pages, rewrite rules for nginx, Apache and WordPress, soft 404s, and redirects that stop lost traffic.4 min readError fix · Server errorsHTTP 405 Method Not Allowed: Fix GET, POST and OPTIONS ErrorsFix HTTP 405 Method Not Allowed: read the Allow header, correct form and API methods, nginx static POST, Apache limits, CORS preflight and redirect method changes.4 min readError fix · Server errorsHTTP 408 Request Timeout: Causes and Fixes for Slow ClientsFix HTTP 408 Request Timeout: why servers close idle or slow uploads, and how to tune nginx, Apache, load balancer and client timeouts without opening yourself to slowloris.4 min readError fix · Server errorsHTTP 410 Gone: What It Means and When to Use It Instead of 404HTTP 410 Gone says content was removed on purpose. Learn how to fix accidental 410s, serve 410 correctly in nginx and Apache, and how Google treats it versus 404.4 min readError fix · Server errorsHTTP 415 Unsupported Media Type: Fix Content-Type Errors in APIsFix HTTP 415 Unsupported Media Type: send the correct Content-Type, match what the API accepts, handle charset and multipart uploads, and debug Spring, Express and Laravel.4 min readError fix · Server errorsHTTP 422 Unprocessable Content: Fix Validation Errors in APIsFix HTTP 422 Unprocessable Content (Unprocessable Entity): read the validation body, fix field types and rules in Laravel, Rails, FastAPI and Express, and handle CSRF tokens.4 min readError fix · Server errorsHTTP 431 Request Header Fields Too Large: Cookie and Header FixesFix HTTP 431 Request Header Fields Too Large: clear bloated cookies, trim headers, and raise nginx, Apache, Node.js and proxy header limits only when needed.4 min readError fix · Server errorsHTTP 451 Unavailable For Legal Reasons: What It Means and OptionsHTTP 451 means content is blocked because of a legal demand. Learn what visitors can do, and how site owners should implement and diagnose 451 correctly.4 min readError fix · Server errorsHTTP 500 Internal Server Error: Where to Find the Cause in Your LogsFind the real cause of an HTTP 500 by reading the right log for your stack: nginx, Apache, PHP-FPM, WordPress, Laravel, Node.js, Python, Rails and Java.4 min readError fix · Server errorsHTTP 503 Retry-After and Maintenance Pages: Doing It RightServe a proper 503 Service Unavailable with a Retry-After header for maintenance windows, with nginx, Apache and CDN examples and notes on SEO and caching.4 min readError fix · Server errorsHTTP 505 HTTP Version Not Supported: Causes and FixesFix HTTP 505 Version Not Supported. Learn why a server rejects an HTTP version, from h2c and HTTP/1.0 proxies to malformed request lines, and how to correct it.4 min readError fix · Server errorsHTTP 507 Insufficient Storage: Free Disk Space and Fix QuotasHTTP 507 Insufficient Storage means the server cannot store what the request needs. Check disk space, inodes and quotas, then fix WebDAV and upload failures.5 min readError fix · Server errorsHTTP 508 Loop Detected and Resource Limit Is Reached: FixesFix HTTP 508 Loop Detected. It means a request cycle on WebDAV, and on CloudLinux hosts it appears as Resource Limit Is Reached. Find the cause and fix it.4 min readError fix · Server errorsMySQL "Server Has Gone Away" (Error 2006): Causes and FixesFix MySQL error 2006 "MySQL server has gone away" and 2013 "Lost connection during query" by checking timeouts, max_allowed_packet, crashes and idle connections.4 min readError fix · Server errorsMySQL "Too Many Connections" (Error 1040): Causes and FixesFix MySQL and MariaDB error 1040 Too many connections: see who holds the connections, raise max_connections safely, and stop apps from leaking them.4 min readError fix · Server errorsMySQL Error 2002: Can't Connect to Local MySQL Server (Fix)Fix MySQL and MariaDB error 2002 "Can't connect to local MySQL server through socket" by checking the service, socket path, bind address and firewall.4 min readError fix · Server errorsnginx 'directory index of "/path/" is forbidden' (403) Fixnginx returns 403 with "directory index of is forbidden" when a folder has no index file and autoindex is off. Add the index, fix the root, or enable listings safely.4 min readError fix · Server errorsnginx "connect() failed (111: Connection refused)" Upstream FixFix nginx "connect() failed (111: Connection refused) while connecting to upstream" by checking that PHP-FPM or your app listens where nginx expects.4 min readError fix · Server errorsnginx "could not build server_names_hash": Increase Bucket SizeFix the nginx emerg error "could not build server_names_hash, you should increase server_names_hash_bucket_size" with the right http-level values and a way to find the cause.4 min readError fix · Server errorsnginx "no live upstreams while connecting to upstream" Fixnginx logs no live upstreams when every server in an upstream block is marked failed. Learn why it happens and how to tune max_fails and fail_timeout.4 min readError fix · Server errorsnginx "rewrite or internal redirection cycle" (500) FixFix nginx 500 errors logged as rewrite or internal redirection cycle by finding the try_files, rewrite or error_page rule that keeps sending requests back to itself.3 min readError fix · Server errorsnginx "socket() failed (24: Too many open files)" FixFix nginx too many open files errors by raising worker_rlimit_nofile, the systemd LimitNOFILE value and system limits, then verify the real limits on workers.4 min readError fix · Server errorsnginx "SSL_do_handshake() failed": What Each Variant MeansDecode nginx SSL_do_handshake() failed log lines (wrong version number, no shared cipher, unknown ca, upstream handshakes) and fix client and proxy TLS settings.4 min readError fix · Server errorsnginx "upstream sent too big header" 502 FixFix nginx 502 errors caused by upstream sent too big header while reading response header. Raise proxy_buffer_size or fastcgi_buffer_size correctly.4 min readError fix · Server errorsnginx "upstream timed out (110: Connection timed out)" FixDecode the nginx log line "upstream timed out (110: Connection timed out)" and set the right timeout directive for PHP-FPM, proxy_pass or uWSGI.4 min readError fix · Server errorsnginx "worker_connections are not enough" FixFix the nginx worker_connections are not enough error by sizing worker_connections, worker_rlimit_nofile and the OS file limit, and by cutting wasted connections.4 min readError fix · Server errorsnginx 400 Request Header Or Cookie Too Large: How to Fix ItFix nginx 400 Bad Request "Request Header Or Cookie Too Large" by clearing bloated cookies and tuning large_client_header_buffers safely.5 min readError fix · Server errorsnginx 403 Forbidden: Diagnose by Error Log Message and FixDiagnose an nginx 403 Forbidden using the exact error log line: permissions, missing index, deny rules, SELinux, symlinks or an upstream. Includes a decision order.4 min readError fix · Server errorsnginx 404 for Files That Exist: root, alias and try_files Fixesnginx returns 404 although the file is on disk? Check root versus alias, location matching, try_files order, case, symlinks and the wrong server block, using the error log.4 min readError fix · Server errorsnginx 413 Request Entity Too Large: client_max_body_size FixFix nginx 413 Request Entity Too Large by raising client_max_body_size, then check PHP, Apache, ingress and CDN limits that can also reject uploads.4 min readError fix · Server errorsnginx 499 Client Closed Request: What It Means and When to Actnginx logs 499 when the client disconnects before the response. Learn the causes, how to find slow upstreams, and how proxy_ignore_client_abort works.4 min readError fix · Server errorsPHP "Allowed memory size exhausted" Error: Causes and FixesFix PHP's "Allowed memory size exhausted" fatal error: find the memory_limit actually in effect, raise it in the right place, and fix the memory hog.5 min readError fix · Server errorsPHP Parse Error: syntax error, unexpected token (How to Fix)Understand PHP "Parse error: syntax error, unexpected token" messages, find the broken line with php -l, and fix missing semicolons, braces and version mismatches.5 min readError fix · Server errorsWordPress "Cookies are blocked due to unexpected output" Login FixFix the WordPress login errors "Cookies are blocked due to unexpected output" and "Cookies are blocked or not supported by your browser" step by step.4 min readError fix · Server errorsWordPress "Publishing failed. You are probably offline" FixFix WordPress "Publishing failed" messages, including "You are probably offline" and rest_cookie_invalid_nonce, by checking login state, REST access and caching.4 min readError fix · Server errorsWordPress "The link you followed has expired" Error FixFix "The link you followed has expired" in WordPress, usually caused by a theme or plugin upload larger than PHP's post_max_size or upload limits.4 min readError fix · Server errorsWordPress "There has been a critical error on this website" FixFix the WordPress message "There has been a critical error on this website" by reading the recovery email, the PHP error log and disabling the failing plugin or theme.4 min readError fix · Server errorsWordPress Installation Failed: Could Not Create Directory - FixFix WordPress plugin or theme install errors like Could not create directory by correcting ownership, permissions, disk quota, leftover folders and FS_METHOD.4 min readError fix · Server errorsWordPress Posts Return 404 Not Found After Changing PermalinksFix WordPress posts and pages showing 404 Not Found while the home page works: flush rewrite rules, repair .htaccess, enable mod_rewrite or add the nginx try_files line.4 min readError fix · Server errorsWordPress Site Health "REST API error" and "Loopback request failedFix the Site Health warnings "The REST API encountered an error" and "Your site could not complete a loopback request" by finding the cURL or HTTP error behind them.4 min read