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.
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, sowarn,noticeandinfomessages 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
serverorlocationblock with its ownerror_logsends 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 logsinstead. - 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-levelerror_logwithoutdebugturns 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
The path is set at build time and can be overridden in the config, so check before assuming.
- Print the path compiled into your nginx build.
nginx -V 2>&1 | sed -n 's/.*--error-log-path=\([^ ]*\).*/\1/p' - Check which
error_loglines the active config (including included files) uses. Paths vary between builds and systems, so trust this output over any example path.nginx -T | grep error_log - Follow the log live while you repeat the failing request. The nginx beginner's guide names
/usr/local/nginx/logsand/var/log/nginxas the usual directories; use whatever the previous steps showed.tail -f /var/log/nginx/error.log - In a Docker container, read the output through Docker instead.
docker logs <container>
2.Raise the log level and reload
At the default error level, warnings and notices are hidden. A level also logs everything more severe than itself.
- Levels from least to most severe are
debug,info,notice,warn,error,crit,alert,emerg. Setwarnorinfoin the main config.error_log /var/log/nginx/error.log warn; - 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.
nginx -s reload
3.Fix a conflicting error_log in a server or location block
If messages vanish, another error_log closer to the failing request may be catching them.
- Run
nginx -T | grep -n error_logand look forerror_loglines insideserverorlocationblocks. - Either remove the extra line, or give it the level you want, for example
debug. A lower-levelerror_logoverrides the inherited one. Severalerror_loglines at the same level all receive the message (1.5.2 and newer). - Reload as above.
4.Fix an empty log after rotation
nginx keeps its log files open. Renaming a file does not make nginx switch to a new one.
- Rename the current log, then send the USR1 signal to the master process.
mv /var/log/nginx/error.log /var/log/nginx/error.log.1 - 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
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.
- Check that your build supports debug.
nginx -V 2>&1 | grep -- --with-debug - If it does not, official Linux packages (1.9.8 and newer) include an
nginx-debugbinary. Stop the normal service and start that one.service nginx stop service nginx-debug start - Enable debug for only selected client addresses.
error_log /path/to/log; events { debug_connection 192.168.1.1; debug_connection 192.168.10.0/24; } - 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.
error_log memory:32m debug; - When finished, remove the debug settings and reload.
6.Send the error log to syslog
Useful when you collect logs centrally or want a destination other than a file.
- Point
error_logat a syslog target. The default syslog port is 514.error_log syslog:server=unix:/var/log/nginx.sock warn; - Reload nginx.
7.Adjust the documented limits behind common failures
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.
- 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_passuseproxy_read_timeout; for FastCGI usefastcgi_read_timeout; for uwsgi useuwsgi_read_timeout; for gRPC usegrpc_read_timeout. The timeout applies between two successive reads, not to the whole response.proxy_read_timeout 120s; - For a 413 response, the request body is bigger than
client_max_body_size, which defaults to1m. Raise it;0disables the check.client_max_body_size 20m; - If connection limits are the problem, raise
worker_connections(set in theeventsblock) andworker_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. - Reload nginx and repeat the request.
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
debugsetting is removed and the log is no longer growing quickly.
If it still fails
- Run
nginx -Tand read the whole effective config for overlappingerror_loglines 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
- Module ngx_core_moduleOfficial · nginx.org
- A debugging logOfficial · nginx.org
- Controlling nginxOfficial · nginx.org
- Beginner's GuideOfficial · nginx.org
- Configuring LoggingOfficial · F5 NGINX docs
- Module ngx_http_proxy_moduleOfficial · nginx.org
- Module ngx_http_fastcgi_moduleOfficial · nginx.org
- Module ngx_http_uwsgi_moduleOfficial · nginx.org
- Module ngx_http_grpc_moduleOfficial · nginx.org
- Module ngx_http_core_moduleOfficial · nginx.org