Nginx error logs: where they are, how to read them and what to change

The nginx error log is controlled by the `error_log` directive, and its path depends on how nginx was built. Find it with `nginx -V` and `nginx -T`, read it with `tail -f`, and lower the level to `warn` or `info` if you need more detail.

Applies to:nginx open sourceall versions (some options need 1.7.11 or newer)NGINX Plus
On this page

What it means

The nginx error log is where nginx writes its own diagnostics: configuration problems, upstream and proxy failures, file and permission errors, and resource limits. It is separate from the access log, which only records requests. When a page returns 502, 504 or 413, the reason is usually written here.

This page covers finding the log, getting more detail out of it, rotating it, and the documented limits (timeouts, body size, connections) that most often explain what you see. To go from a status code straight to a fix, see nginx error: how to find the cause and fix 502, 504, 413 and 414.

Symptoms and causes

You are likely dealing with this problem if:

  • Pages return 502, 504 or 413.
  • nginx fails to start or reload.
  • The log file is missing, or empty after rotation.
  • Proxied requests are slow or fail.

The usual causes, most common first:

The log level is too high
The default level is error, so warn, notice and info messages are never written.
Another error_log overrides the one you are reading
Each message goes only to the error log closest to where the problem happened. A server or location block with its own error_log sends messages to a different file.
No file exists (Docker or stderr)
Docker images link the error log to stderr, so there is no file to open. Use docker logs instead.
The log was rotated but nginx still holds the old file
After a log file is renamed, nginx must be told to reopen its log files, otherwise it keeps writing to the renamed file and the new one stays empty.
Debug output is missing
The nginx binary was built without --with-debug, or a server-level error_log without debug turns debug off for that server.
Config changes were not reloaded
nginx keeps using the old configuration until it is reloaded or restarted.

How to fix it

Work through these in order. They start with the quickest, safest checks and move to deeper repairs; stop as soon as the problem is gone.

1.Find and read the log

Easy

The path is set at build time and can be overridden in the config, so check before assuming.

  1. Print the path compiled into your nginx build.
    Terminal
    nginx -V 2>&1 | sed -n 's/.*--error-log-path=\([^ ]*\).*/\1/p'
  2. Check which error_log lines the active config (including included files) uses. Paths vary between builds and systems, so trust this output over any example path.
    Terminalneeds sudo / root
    nginx -T | grep error_log
  3. Follow the log live while you repeat the failing request. The nginx beginner's guide names /usr/local/nginx/logs and /var/log/nginx as the usual directories; use whatever the previous steps showed.
    Terminalneeds sudo / root
    tail -f /var/log/nginx/error.log
  4. In a Docker container, read the output through Docker instead.
    Terminal
    docker logs <container>

2.Raise the log level and reload

Easy

At the default error level, warnings and notices are hidden. A level also logs everything more severe than itself.

  1. Levels from least to most severe are debug, info, notice, warn, error, crit, alert, emerg. Set warn or info in the main config.
    nginx.conf
    error_log /var/log/nginx/error.log warn;
  2. Reload nginx. On reload the master process checks the new configuration first and, if it is invalid, keeps working with the old one, so check the log for errors afterwards.
    Terminalneeds sudo / root
    nginx -s reload

3.Fix a conflicting error_log in a server or location block

Moderate

If messages vanish, another error_log closer to the failing request may be catching them.

  1. Run nginx -T | grep -n error_log and look for error_log lines inside server or location blocks.
  2. Either remove the extra line, or give it the level you want, for example debug. A lower-level error_log overrides the inherited one. Several error_log lines at the same level all receive the message (1.5.2 and newer).
  3. Reload as above.

4.Fix an empty log after rotation

Moderate

nginx keeps its log files open. Renaming a file does not make nginx switch to a new one.

  1. Rename the current log, then send the USR1 signal to the master process.
    Terminalneeds sudo / root
    mv /var/log/nginx/error.log /var/log/nginx/error.log.1
  2. If the log directory itself is not writable by the user the workers run as, or the disk is full, nginx cannot write there. Check both.

5.Turn on debug logging for one problem

AdvancedChanges settings

Debug logs show what nginx is doing step by step, which helps when info is not enough.

Before you start: Debug logging is very verbose and can fill the disk. It can also record full request headers and bodies, which may include cookies, Authorization headers and tokens. Treat debug logs as sensitive: redact secrets before posting them on a forum or sending them to anyone, and turn debug off when you are done.

  1. Check that your build supports debug.
    Terminal
    nginx -V 2>&1 | grep -- --with-debug
  2. If it does not, official Linux packages (1.9.8 and newer) include an nginx-debug binary. Stop the normal service and start that one.
    Terminalneeds sudo / root
    service nginx stop
    service nginx-debug start
  3. Enable debug for only selected client addresses.
    nginx.conf
    error_log /path/to/log;
    events {
        debug_connection 192.168.1.1;
        debug_connection 192.168.10.0/24;
    }
  4. Alternatively, write debug output to a cyclic memory buffer (1.7.11 and newer). The docs say it has no significant performance impact under high load, but the buffer is only useful if you can extract it with gdb or lldb scripts. Without that access, use the file-based option above.
    nginx.conf
    error_log memory:32m debug;
  5. When finished, remove the debug settings and reload.

6.Send the error log to syslog

Moderate

Useful when you collect logs centrally or want a destination other than a file.

  1. Point error_log at a syslog target. The default syslog port is 514.
    nginx.conf
    error_log syslog:server=unix:/var/log/nginx.sock warn;
  2. Reload nginx.

7.Adjust the documented limits behind common failures

ModerateChanges settings

These are the limits the nginx documentation defines, with their defaults. If the log points at one of them, raising it is the matching change. They do not replace checking that the backend is actually running and reachable.

Before you start: Back up the config file before editing. Raising limits has side effects, so change one value at a time.

  1. If the log shows the backend timing out while nginx waits for its response, raise the read timeout for the directive type you use. The default for each is 60s. For proxy_pass use proxy_read_timeout; for FastCGI use fastcgi_read_timeout; for uwsgi use uwsgi_read_timeout; for gRPC use grpc_read_timeout. The timeout applies between two successive reads, not to the whole response.
    nginx.conf
    proxy_read_timeout 120s;
  2. For a 413 response, the request body is bigger than client_max_body_size, which defaults to 1m. Raise it; 0 disables the check.
    nginx.conf
    client_max_body_size 20m;
  3. If connection limits are the problem, raise worker_connections (set in the events block) and worker_rlimit_nofile. Proxied connections count too, so a proxied request can use two, and the effective number is capped by the open-file limit. Packaged configs often override the documented default of 512, so read your own value first.
  4. Reload nginx and repeat the request.
    Terminalneeds sudo / root
    nginx -s reload

Check that it worked

  • Repeat the failing request and confirm a new line appears in the log with the expected level.
  • After rotation, confirm the new log file receives lines and the old one stops growing.
  • After debugging, confirm the debug setting is removed and the log is no longer growing quickly.

If it still fails

  • Run nginx -T and read the whole effective config for overlapping error_log lines and wrong paths.
  • Check that the user the workers run as can write to the log directory, and that the disk is not full.
  • Use the debug log limited to your own client address and read it around the failing request.
  • For the status code itself, see nginx error: how to find the cause and fix 502, 504, 413 and 414. If you ask for help on the official nginx support channels, redact IP addresses, cookies, tokens and Authorization headers from any log lines first, especially debug output.

Questions

Does a log level also include more serious messages?

Yes. Setting warn also records error, crit, alert and emerg.

Can nginx write the error log as JSON?

The ngx_core_module page lists a json parameter for error_log (1.29.8) that is available only with a commercial subscription. It is not supported together with debug logging.

Sources

  1. Module ngx_core_moduleOfficial · nginx.org
  2. A debugging logOfficial · nginx.org
  3. Controlling nginxOfficial · nginx.org
  4. Beginner's GuideOfficial · nginx.org
  5. Configuring LoggingOfficial · F5 NGINX docs
  6. Module ngx_http_proxy_moduleOfficial · nginx.org
  7. Module ngx_http_fastcgi_moduleOfficial · nginx.org
  8. Module ngx_http_uwsgi_moduleOfficial · nginx.org
  9. Module ngx_http_grpc_moduleOfficial · nginx.org
  10. Module ngx_http_core_moduleOfficial · nginx.org