Nginx Access and Error Logs: Where to Find Them and How to Read Them

When a site on your server breaks, the nginx access and error logs are usually the first place that tells you what happened. They record every request the server handled and every problem it hit while doing so. If you know where these files live and how to read a line, you can find a broken page, a failing upstream, or a flood of bad requests in minutes instead of guessing through config files.

This guide covers the default log locations on Ubuntu and Debian, the format of each log line, and the commands that make large logs readable. It assumes a standard Nginx install from the system packages, not a Docker container or a control panel that moves logs elsewhere.

Where Nginx Keeps Its Logs by Default

On Ubuntu and Debian, the global logs live in /var/log/nginx/. The two files you will see most often are access.log and error.log. The global paths are set in the main config file, /etc/nginx/nginx.conf, with the access_log and error_log directives. Individual sites can override these paths inside their server blocks, so a virtual host may write to its own file such as /var/log/nginx/example.com.access.log.

To find the active paths for a running server, check the main config and then each enabled site config in /etc/nginx/sites-enabled/. If a site sets its own log path, that file is the one that matters for that site. The global file still records requests that do not match any server block, which is useful when a request lands on the default site.

Log rotation is handled by logrotate on most systems. Old files get compressed names such as access.log.1.gz. You can read a compressed log with zcat or zgrep instead of decompressing it first.

How to Read Nginx Access and Error Logs Line by Line

A default access log line looks like a wall of fields, but each field has a fixed position. A typical line records the client IP, the time, the request, the status code, the response size, the referrer, and the user agent. Once you know that order, you can scan a line from left to right and stop at the field that answers your question.

The nginx log format is fixed by default, so each field sits in the same position on every line. To read nginx access log entries quickly, scan the status code first. The status code is the fastest triage tool. A run of 404s points to missing files or wrong paths. A run of 502s points to an upstream problem, such as PHP-FPM being down. A run of 403s often means a permission problem or a rule that blocks the request. The request field shows the exact path that was asked for, which helps you tell a real broken link apart from a scanner probing random paths.

For a closer look at one site, filter with grep. Searching for a status code, an IP address, or a path narrows thousands of lines to the ones that matter. If you want to watch requests arrive in real time, tail -f /var/log/nginx/access.log shows each new line as Nginx writes it, which is handy while you reproduce a problem in a browser.

How to Read an Nginx Error Log Line

The nginx error log location is the same directory, but the content is different. Error log lines carry a timestamp, a severity level, a process and connection identifier, and a message that describes what failed. Severity levels run from debug up to emerg, and the default level is error, which means warnings and below are not written unless you change the setting.

Common messages are worth learning by sight. A “no such file or directory” message while opening a file means the path in the config does not match the file on disk. A “connection refused” message while connecting to an upstream means the backend service is not listening on the expected port. A “permission denied” message usually means the Nginx worker user cannot read the file, which is a file ownership or permission problem rather than a config syntax problem.

When you need more detail, raise the error log level for one site to warn or notice, reproduce the problem, then set it back. Leaving a server on debug level fills disks fast on a busy site, so treat a raised level as a temporary diagnostic step, not a permanent setting. Our guide to fixing 502 Bad Gateway errors in Nginx shows how error log messages map to specific upstream failures.

Useful Commands for Searching Logs

Large logs reward a few basic tools. Use grep to filter by IP, path, or status code. Use awk to pull out one field, such as the status code column, and count how often each value appears. Use sort and uniq -c to rank the most frequent IPs or paths, which is how you spot one client hammering the server.

For time-based searches, grep with a date string works when the log volume is small. On a busy server, consider a log viewer or shipping logs to a central tool, because grepping a multi-gigabyte file on every incident gets slow. Even then, the same line format applies, so the reading skill transfers directly.

If a log file is missing entirely, check two things before anything else: whether the directory exists and is writable by the Nginx worker user, and whether the config actually contains an access_log or error_log directive for that site. A site with logging turned off with access_log off; writes nothing, which is a valid choice for a high-traffic static asset host but a confusing one when you expect entries. Rate limiting can also cut log noise from abusive clients, as covered in our Nginx rate limiting guide.

Common Mistakes When Reading Logs

The most common mistake is reading the wrong file. A server block with its own log path will not appear in the global log, and the global log will not explain a site-specific failure. Always confirm which file a site writes to before drawing conclusions.

The second mistake is treating every 404 as a problem. Scanners probe for admin panels and backup files all day, and those 404s are normal background noise. Focus on 404s for paths your own site should serve, and on errors that match a user report in time.

The third mistake is ignoring timestamps. Logs record server local time, and a mismatch between the log clock and the time a user reported a problem sends you hunting through the wrong slice of the file. Check the server clock with date and convert the report time before you search. When a 404 turns out to be a fresh-install path problem rather than a missing file, our guide to fixing Nginx 404 errors on a fresh install walks through the usual causes.

Putting It Together on a Real Incident

A practical workflow looks like this. A user reports a blank page at a known time. You check the error log around that time and find an upstream connection error. You check the access log for the same minute and see 502s for that path only. That combination points at the backend for that site, not at Nginx itself, so you check the backend service next instead of rewriting Nginx config.

Keep this habit for every incident: confirm the log file, match the timestamp, read the status code, then read the error message. Four steps, in that order, solve most Nginx problems faster than changing settings at random and hoping the error goes away.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.