webzod
account

Fix the server error on robots.txt on nginx

hygiene.robots.server_error · effort: about an hour

Why it matters

While robots.txt answers with a 5xx error, Google stops crawling the site for about 12 hours, then relies on its last good copy for up to 30 days. The cause is usually a failing backend, a script that builds the file, or a firewall.

The fix

  1. Check the nginx error log (often /var/log/nginx/error.log) for the failing request, and check whether the upstream app answers.
  2. Create /var/www/html/robots.txt first (the generic fix shows what to put in it). Then add an exact-match location that serves it regardless of the app, run nginx -t and reload nginx. Without the file this location answers 404 instead of the app's answer.
/etc/nginx/conf.d/example.com.conf
location = /robots.txt {
    root /var/www/html;
    default_type text/plain;
}

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.