Check 05.13 · HTTP and redirects

Fix 5xx errors

Diagnose and fix 500, 502, 503, 504 and 52x errors: logs, PHP-FPM, timeouts, memory, Cloudflare, AWS, WordPress, Laravel, then validate in Search Console.

Priority
Critical
Difficulty
Advanced
Estimated time
1 h to several days
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

A 5xx error means the server could not respond: the application failed (500), an upstream service was unreachable (502), the server is overloaded or unavailable (503), or a timeout was exceeded (504). Crawlers draw the same conclusion as visitors: the site is fragile. This task consists of identifying the URLs and the times affected, finding the exact cause in the logs, fixing it at the root, then having Google validate the fix. Expected result: a 5xx rate close to zero, and no URL under “Server error (5xx)” in Search Console.

Why it matters

Google documents the effect of server errors on its crawlers:

  • Slower crawling: 5xx and 429 codes make Google's crawlers temporarily slow down, in proportion to the number of URLs in error. The pace gradually picks up again once responses are back to 2xx.
  • Removal from the index: already indexed URLs that return a server error are kept at first, then removed if the error persists.
  • robots.txt: if it returns 5xx, Google stops crawling the whole site for the first 12 hours, then relies on the last known version.

Generative engines suffer the same outages: a retrieval crawler that reads your page during an error gets an empty page and cites another source.

5xx errors rarely have a single cause. An intermittent error on a heavy template, invisible during normal browsing, can affect thousands of URLs crawled by bots, which precisely request deep pages that are rarely cached.

What it improves

  • Indexing URLs no longer drop out of the index because of repeated errors, and those that had dropped out come back after a fresh crawl.
  • Crawling Google returns to a normal pace across the whole hostname.
  • Availability for AI assistants Live retrievals succeed. That still does not guarantee citations.
  • Conversions A 5xx error on a product page or a checkout flow is a lost sale. This is the most direct effect.
  • Response time The fixes (cache, queries, processes) often speed up the whole site.

How to check

1. Search Console. In the Page indexing report, open “Server error (5xx)” and note the templates concerned. In Crawl stats, look at the breakdown of responses and the host status.

2. The logs, code by code and URL by URL:

awk '$9 ~ /^5/ {print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
awk '$9 ~ /^5/ {print $9, $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -30

3. Reproduce. Request a URL in error several times, with the response time:

for i in $(seq 1 10); do curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" https://example.com/categorie/page-lourde/; done

A constant error points to a bug; an intermittent error, or one accompanied by long response times, points to saturation or a timeout.

4. Read the code before looking for the cause:

Code Meaning Where to look
500 The application failed Application log, PHP log
502 The proxy did not get a valid response from the upstream service Nginx error log, status of PHP-FPM or the Node process
503 Service unavailable: overload, maintenance, limit Saturated processes, host limits, maintenance mode
504 The upstream service did not respond in time Slow queries, calls to external APIs
508 Account resource limit (CloudLinux) Hosting resource usage
520 to 526 Cloudflare-specific errors between Cloudflare and the origin Origin, firewall, certificate

How to implement

Before you start

Method, whatever the environment:

  1. Narrow it down: which URLs, which template, since when, at what time, for which clients (everyone, crawlers only, one region).
  2. Correlate with recent changes: deployment, plugin update, traffic spike, nightly backup, renewed certificate.
  3. Read the error log at the exact time of an error found in the access log.
  4. Fix the cause, not the symptom: raising a timeout hides a slow query that will eventually saturate the server.
  5. Validate: curl test, log monitoring for 24 to 48 h, then “Validate Fix” in Search Console.

For planned maintenance, 503 is the right response: see use 503 during temporary maintenance (opens in a new tab). To set up continuous detection: monitor server errors (opens in a new tab).

Nginx

Versions Nginx 1.18 and later, PHP-FPM 8.1 and later.

The error log gives the cause of 502s and 504s:

sudo grep -E "upstream timed out|connect\(\) failed|upstream prematurely closed|no live upstreams|Resource temporarily unavailable" /var/log/nginx/error.log | tail -20
Message Cause Fix
connect() to unix:/run/php/php8.4-fpm.sock failed (2: No such file…) PHP-FPM stopped or socket misnamed sudo systemctl status php8.4-fpm, fix the path in fastcgi_pass
(11: Resource temporarily unavailable) PHP-FPM queue full Increase pm.max_children (see PHP-FPM)
upstream prematurely closed connection PHP process killed (memory, timeout) PHP-FPM log, memory_limit
upstream timed out (110: Connection timed out) Response too slow Optimize the page, and only then adjust the timeout

The default fastcgi_read_timeout and proxy_read_timeout values are 60 seconds. Genuinely long processing (export, import) should go through a queue rather than a raised timeout. If needed, on a specific location:

location ^~ /admin/export {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_pass unix:/run/php/php8.4-fpm.sock;
    fastcgi_read_timeout 300s;
}

Reload with sudo nginx -t && sudo systemctl reload nginx.

PHP-FPM

PHP-FPM reports its own saturation:

sudo grep -E "max_children|terminated|exited on signal" /var/log/php8.4-fpm.log | tail -20

A message saying that pm.max_children has been reached means requests are waiting for a free process. Measure the average memory of a process, then size accordingly: memory available for PHP divided by the memory of one process.

ps -o rss= -C php-fpm8.4 | awk '{s += $1; n++} END {printf "%d processes, %.0f MB on average\n", n, s / n / 1024}'

In /etc/php/8.4/fpm/pool.d/www.conf:

pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
request_slowlog_timeout = 5s
slowlog = /var/log/php8.4-fpm-slow.log

The slowlog records the call stack of requests that take longer than five seconds: that is where you find the SQL query or the API call at fault. Adjust the version number, then run sudo systemctl reload php8.4-fpm.

Apache

Versions Apache 2.4 with the event MPM.

sudo grep -E "MaxRequestWorkers|AH00161|Premature end of script|AH01067|PHP Fatal" /var/log/apache2/error.log | tail -20
  • server reached MaxRequestWorkers setting: all processes are busy. Raise MaxRequestWorkers in /etc/apache2/mods-available/mpm_event.conf if memory allows, and add a page cache.
  • PHP Fatal error: a code error, see the section for your CMS or framework.
  • Premature end of script headers or FastCGI errors: the PHP process stopped, often because of insufficient memory or an exceeded timeout.

Reload with sudo apachectl configtest && sudo systemctl reload apache2.

Cloudflare

Versions Cloudflare dashboard, all plans (524 timeout adjustable on Enterprise only), November 2026.

52x codes refer to the connection between Cloudflare and your origin:

Code Cause Fix
520 Empty or invalid response from the origin Origin logs, headers too large
521 The origin refuses the connection Server down, firewall blocking Cloudflare's ranges
522 Connection timed out Saturated origin, firewall, wrong address in DNS
524 The origin did not respond within 125 seconds Processing too long, to be moved to a background task
525, 526 TLS failure, invalid origin certificate Origin certificate, SSL/TLS mode

The 125-second timeout behind the 524 can only be changed on the Enterprise plan: move long-running processing to a non-proxied subdomain or an asynchronous task. Allow Cloudflare's IP ranges in the origin's firewall to prevent 521s and 522s.

The Always Online feature, in Caching > Configuration, serves a cached or archived copy when the origin is unreachable (52x errors), not when the origin itself returns a 500. It also enables the Internet Archive integration. It is a safety net, not a fix.

AWS

Versions AWS console (Application Load Balancer, CloudFront, CloudWatch), November 2026.

Application Load Balancer: the CloudWatch metrics distinguish HTTPCode_ELB_5XX_Count (the load balancer itself) from HTTPCode_Target_5XX_Count (your instances).

  • 503 from the load balancer: no healthy target. Check the path and the expected code of the target group's health check.
  • 502: the target closed the connection or returned an invalid response. Keep the web server's keepalive longer than the load balancer's idle timeout.
  • 504: the target did not respond within the idle timeout, 60 seconds by default.

CloudFront caches 5xx errors from the origin for 10 seconds by default (Error Caching Minimum TTL setting, per code, in the Error pages tab). A longer value relieves a struggling origin, but prolongs the error after the repair: invalidate the affected URLs once the cause has been fixed.

Plesk

Versions Plesk Obsidian 18.0.

Domain logs: Websites & Domains > your domain > Logs, filtered on errors, or on disk in /var/www/vhosts/system/example.com/logs/. The domain's PHP-FPM settings (maximum number of processes, memory_limit, max_execution_time) are in the domain's PHP Settings. Adjust them as in the PHP-FPM section.

cPanel

Versions cPanel & WHM 110 and later, Jupiter theme.

Metrics > Errors displays the latest entries in the error log. Software > MultiPHP INI Editor sets memory_limit and max_execution_time. Recurring 503 or 508 errors on a CloudLinux server often reflect exhaustion of the account's resources: check Metrics > Resource Usage when the host enables it.

Shared hosting

You cannot always see the server log. Enable your CMS's error log (see WordPress), note the exact times of the errors in Search Console or your access logs, and send them to support. 503s every night at a fixed time often point to a backup or a scheduled task that is too heavy; 503s at peak times point to an undersized plan that only a page cache or an upgrade will solve.

WordPress

Versions WordPress 6.4 to 7.1, WP-CLI 2.x.

The message “There has been a critical error on this website” corresponds to a 500 error. WordPress then sends a recovery mode email to the admin address, with a link that lets you deactivate the faulty plugin or theme.

Enable the log in wp-config.php, without public display:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_MEMORY_LIMIT', '256M' );

Errors are written to wp-content/debug.log. If the admin is inaccessible, deactivate the plugins from the command line, then reactivate them one by one:

wp plugin deactivate --all
wp plugin activate woocommerce

Without SSH access, rename the wp-content/plugins folder over FTP. Set WP_DEBUG back to false once the cause has been found. Query Monitor then helps spot the slow queries responsible for 504s.

Laravel

Versions Laravel 10 to 13.

Unhandled exceptions produce a 500 and are written to storage/logs/laravel.log:

tail -n 100 storage/logs/laravel.log | grep -E "production\.(ERROR|CRITICAL)"

Common causes after a deployment: permissions on storage/ and bootstrap/cache/, stale cached configuration, a migration that was not run, a missing PHP extension.

php artisan optimize:clear
php artisan migrate --force
php artisan optimize
sudo chown -R www-data:www-data storage bootstrap/cache

Keep APP_DEBUG=false in production. For 504s, look for slow queries (optimize database queries (opens in a new tab)) and move long-running processing into queued jobs.

Next.js

Versions Next.js 15 and 16. Error handling differs between the App Router and the Pages Router.

A server-side rendering error or a failed data fetch produces a 500. Read the process logs (pm2 logs, journalctl -u nom-du-service) or, on Vercel, the project's Logs tab filtered on 5xx codes. Exceeding the function execution time limit also produces an error: check the limit of your plan. Then handle expected data errors so that they do not turn into 500s.

App Router

For a missing resource, call notFound() in the page or the server component: Next.js returns a 404. Add app/error.js to display a segment's unexpected errors cleanly, and app/global-error.js for those of the root layout.

Pages Router

For a missing resource, return { notFound: true } from getServerSideProps or getStaticProps: Next.js returns a 404. Add pages/500.js for a clean server error page.

Validate the fix in Search Console

Once the errors have been gone from the logs for at least a day, open “Server error (5xx)” in the Page indexing report and click “Validate Fix”. Google recrawls the affected URLs; validation can take several days. For a priority page, request indexing from the URL Inspection tool.

Common mistakes

  • Raising timeouts without looking for the slowness: the error disappears, and saturation arrives later.
  • Leaving WP_DEBUG_DISPLAY or APP_DEBUG on in production: errors are displayed along with sensitive information.
  • Testing only the homepage: it is often cached, while the deep pages crawled by bots fail.
  • Ignoring intermittent errors: 2% of 5xx on a template with 50,000 pages means 1,000 errors received by crawlers.
  • Fixing without validating: without “Validate Fix”, the report takes longer to reflect the repair.
  • Serving an error page with 200: it hides the error from crawlers and your monitoring tools, and becomes a soft 404.
  • Letting robots.txt depend on the application: if it returns 5xx, Google stops all crawling. Serve it as a static file.

Frequently asked questions

Does a 500 error make you lose rankings in Google?

A one-off error, no. Google temporarily slows down its crawling when it receives 5xx errors and keeps already indexed URLs at first. If the error persists on a URL, Google eventually removes it from its index: that is where visibility is lost. Fix it quickly, then request validation in Search Console to speed up recrawling.

What is the difference between a 502 error and a 504 error?

Both come from a proxy or a gateway placed in front of the application. A 502 error means that the upstream service, PHP-FPM or a Node server for example, returned an invalid response or cut the connection. A 504 error means that it did not respond within the allotted time. A 502 points to a process that has stopped or failed, a 504 to a page or a query that is too slow.

How do I fix a 524 error on Cloudflare?

A 524 error means that your server accepted Cloudflare's connection but did not send a response within 125 seconds. This timeout can only be changed on the Enterprise plan. The fix is to speed up the page in question or to move the long-running processing, such as an export, to a background task or a non-proxied subdomain. The origin logs show which URL exceeds the timeout.

How long does Google take to recover after 5xx errors?

Google gradually increases its crawl rate again as soon as the server responds normally, with no fixed timeframe announced. URLs removed from the index come back after being successfully recrawled. To speed things up, click “Validate Fix” in the Page indexing report and request indexing of the most important pages with the URL Inspection tool.

Updated on

Topic checklist (PDF)

And now?

In the “HTTP and redirects” topic

  1. Check that active pages return 200
  2. Use 301/308 for permanent moves
  3. Use 302/307 for temporary moves
  4. Fix redirect chains
  5. Fix redirect loops
  6. Fix broken internal links
  7. Fix broken external links
  8. Create a helpful 404 page
  9. Return 404/410 for removed content with no equivalent
  10. Avoid redirecting all removed pages to the homepage
  11. Fix unjustified 403s
  12. Fix excessive 429s
  13. Fix 5xx errors
  14. Monitor server errors
  15. Use 503 during temporary maintenance