How to check nginx logs: where access.log and error.log are, and why they look empty

/var/log/nginx/access.log can be empty on a server that answers a thousand requests a minute.

Nginx is still logging. It is logging somewhere else. Nginx writes two files. The access log has one line per request. The error log has everything that went wrong. This page covers where both live, how to find the path nginx is using right now, and why either file can be empty.

The quick answer

On most Linux servers both files are in /var/log/nginx/:

sudo tail -f /var/log/nginx/access.log /var/log/nginx/error.log

tail prints a ==> file <== header whenever it switches between files. That shows you which file each line came from.

The package decides the directory:

Installed from Access log Error log
Debian, Ubuntu (apt install nginx) /var/log/nginx/access.log /var/log/nginx/error.log
RHEL, Rocky, Alma, Fedora (dnf install nginx) /var/log/nginx/access.log /var/log/nginx/error.log
Alpine (apk add nginx) /var/log/nginx/access.log /var/log/nginx/error.log
nginx.org packages /var/log/nginx/access.log /var/log/nginx/error.log
Homebrew on macOS $(brew --prefix)/var/log/nginx/access.log $(brew --prefix)/var/log/nginx/error.log
Official nginx Docker image stdout, read with docker logs stderr, read with docker logs
Built from source, no options /usr/local/nginx/logs/access.log /usr/local/nginx/logs/error.log

On Apple Silicon brew --prefix is /opt/homebrew. On Intel Macs it is /usr/local.

Which file do you need?

You want to know Read
Whether a request arrived, and what status it got access log
Why a request got a 502, 504 or 403 error log
Which IP is hammering you access log
Why nginx will not start or reload journalctl -u nginx, then the error log
Why a page is a 404 both. The error log has the full path nginx tried

Find the path nginx is using

A vhost can send its logs anywhere. Ask nginx to print its whole config and filter it:

sudo nginx -T 2>/dev/null | grep -E '# configuration file|(access|error)_log'

-T tests the config and then prints every file it loaded, includes and all. Each file starts with a # configuration file header. The grep keeps those headers and every log directive, so each path sits under the file that sets it:

# configuration file /etc/nginx/nginx.conf:
error_log /var/log/nginx/error.log;
	access_log /var/log/nginx/access.log;
# configuration file /etc/nginx/sites-enabled/shop.conf:
	access_log /var/log/shop/access.log;
	location /api/ { access_log /var/log/shop/api.log; }

That beats grep -r access_log /etc/nginx/. The recursive grep reads files nginx never loads, like a disabled site in sites-available. It also misses includes that live outside /etc/nginx. -T shows exactly what is running. Ignore any matched line that starts with # and is not a file header. Those are commented out.

No access_log or error_log anywhere? Nginx then uses the paths it was compiled with:

nginx -V 2>&1 | tr ' ' '\n' | grep log-path

On Debian 12 and later and Ubuntu 24.04 and later, that prints --error-log-path=stderr. Those packages ship an error_log line in nginx.conf, so you only see this default when nginx fails before it reads the config. Systemd catches stderr, so those messages are in journalctl -u nginx, not in a file.

“syntax is ok”, then “test failed”

Run nginx -t without sudo on Debian or Ubuntu and you get this:

2026/11/15 09:12:04 [warn] 4127#4127: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2026/11/15 09:12:04 [emerg] 4127#4127: open() "/var/log/nginx/error.log" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

The config is fine. The test opens every log file for writing, and your user cannot. Run it with sudo.

Most other packages print one more line first:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

That is the compiled-in error log. Nginx opens it before it reads the config. Same cause, same fix. Debian 12+ and Ubuntu 24.04+ skip this line because their compiled-in error log is stderr.

“Permission denied” when you read the file

Both files are mode 640, so a normal user cannot read them. What else you can do depends on the distribution.

Debian and Ubuntu. The files belong to www-data:adm. Members of the adm group can read them without sudo:

sudo usermod -aG adm "$USER"

Log out and back in for the group to apply.

RHEL, Rocky, Alma and Fedora. The files belong to nginx:root. The directory is mode 711, so you cannot even list it. There is no group to join. Use sudo.

Why access.log is empty or missing requests

The server runs nginx in Docker. The official image links /var/log/nginx/access.log to /dev/stdout and error.log to /dev/stderr. The files exist and stay empty. Docker keeps the two streams apart, so you can split them again:

docker logs --tail 100 web 2>/dev/null       # access log only
docker logs --tail 100 web 2>&1 >/dev/null   # error log only

That split only works if the container was started without -t. A TTY merges both streams into stdout. Viewing Docker container logs has the rest.

A block sets its own access_log. Nginx inherits access_log from the enclosing block only when the inner block sets none. In the -T output above, requests to /api/ go to api.log and never reach access.log. The server block sets its own path too, so the http-level access.log gets nothing from that site at all. nginx -t says nothing about it. Reading nginx access logs covers the fix.

access_log off; Some configs turn logging off for health checks or static files. It is in the -T output if it is anywhere.

Logrotate renamed the file and nginx kept writing to the old one. Nginx holds its log files open. After a rotation, something must tell it to reopen them. The packaged logrotate configs do that. A hand-written one often does not. Check which file is growing:

sudo ls -lt /var/log/nginx/ | head -5

If access.log.1 is newer than access.log, nginx never reopened. Fix it now:

sudo nginx -s reopen

Then add a postrotate step to the logrotate config. Checking nginx error logs has one that works.

Nginx logs to syslog instead. A line like access_log syslog:server=unix:/dev/log,tag=nginx_access sends every request to the journal, and no file is written. Read it with the tag:

journalctl -t nginx_access -n 50

Older logs

Logrotate keeps 14 days on Debian and Ubuntu and 10 on RHEL and Fedora. Older files are deleted. The newest rotated file is .1, and the older ones are gzipped. zgrep reads both kinds:

sudo zgrep -h 'upstream timed out' /var/log/nginx/error.log*

Need more than two weeks? Raise rotate in /etc/logrotate.d/nginx, or keep a copy somewhere else.

The logs are on the server that broke

A 502 at 3 a.m. leaves its error line on one web server. If that server was replaced, the line went with it. Behind a load balancer you also have to guess which server to ssh into.

Send both files to the journal instead, and let the CL Agent ship the journal to one server you control:

access_log syslog:server=unix:/dev/log,tag=nginx_access,severity=info combined;
error_log  syslog:server=unix:/dev/log,tag=nginx_error warn;

The error level goes after a space. It is not one of the comma-separated syslog options. Write tag=nginx_error,warn and nginx -t fails with unknown syslog parameter "warn". Syslog tags take letters, digits and underscores only.

Then point the agent at your server:

# /etc/clagent.toml
URL = "https://logs.example.com/api/v1/ingest_logs/YOUR-SOURCE-TOKEN"

Now one query shows both files from one host, in the order things happened:

SELECT datetime(CAST(json_extract(msg, '$.__REALTIME_TIMESTAMP') AS INTEGER) / 1000000, 'unixepoch') AS at,
       json_extract(msg, '$.SYSLOG_IDENTIFIER') AS file,
       json_extract(msg, '$.MESSAGE')           AS line
FROM logs
WHERE json_valid(msg)
  AND json_extract(msg, '$._HOSTNAME') = 'web-2'
  AND json_extract(msg, '$.SYSLOG_IDENTIFIER') IN ('nginx_access', 'nginx_error')
ORDER BY CAST(json_extract(msg, '$.__REALTIME_TIMESTAMP') AS INTEGER) DESC
LIMIT 100;

The request and the error it caused land next to each other. Sort on __REALTIME_TIMESTAMP, not timestamp. The timestamp column records when the server received the line, so a batch sent after an outage sorts as if it just happened.

Drop the _HOSTNAME line to search every web server at once. Full setup, including a JSON log_format that turns each field into a column, is in sending nginx logs to a central server.

Where to go next

💌 Get notified on new features and updates

Only sent when a new version is released. Nothing else.