Skip to content
Log In Sign Up info@muvcloud.com

Where the Logs Are

ls -l /var/log/nginx/
  • access.log: every request, with the client, the address, and the status code.
  • error.log: failures, such as missing files, refused permissions, and backends that do not answer.
  • access.log.1, access.log.2.gz: older, rotated copies.

Reading them needs sudo, or on Debian and Ubuntu membership in the adm group. Other system logs are listed in Linux log files.

Follow a Log Live

sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log | grep ' 404 '

Load the page you are testing in a browser and watch the line appear. Press Ctrl+C to stop. More options are in the tail command.

The Access Log Format

On Debian and Ubuntu the access log uses the predefined combined format. AlmaLinux, Rocky Linux, and the nginx.org packages use a format named main: the same fields with the X-Forwarded-For header added at the end. A line looks like this:

203.0.113.10 - - [28/Nov/2026:14:02:11 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "curl/8.5.0"
VariableMeaning
$remote_addrClient address
$remote_userUser from basic auth
$time_localTime of the request
$requestMethod, path, protocol
$statusStatus code
$body_bytes_sentSize of the response body
$http_refererPage that linked here
$http_user_agentBrowser or client

To record how long each request took, define your own format in the http block and use it:

log_format timed '$remote_addr [$time_local] "$request" $status '
                 '$body_bytes_sent $request_time';
access_log /var/log/nginx/timed.log timed;

Writing it to a separate file keeps the main log in the standard format that the one-liners below expect.

Per-Site Logs

server {
    server_name example.com;
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log warn;

    location = /health {
        access_log off;
        return 200;
    }
}

A site with its own logs no longer writes to the shared files. access_log off keeps a busy health check out of the log. Run sudo nginx -t and sudo systemctl reload nginx after the change; reload rather than restart, so a mistake leaves the running server untouched.

Error Log Levels

From least to most severe: debug, info, notice, warn, error, crit, alert, and emerg. A level logs itself and everything more severe. The default is error; warn adds useful hints. debug works only in a build with debugging support and writes a great deal.

Useful One-Liners

These assume the combined or main format, where field 1 is the client address and field 9 the status code:

sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
sudo awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
sudo awk '$9 ~ /^5/' /var/log/nginx/access.log | tail -20
sudo zcat /var/log/nginx/access.log.*.gz | awk '{print $9}' | sort | uniq -c

The first lists the busiest client addresses, the second counts each status code, the third shows recent server errors, and the last reads the compressed old logs. See the awk command for more.

Rotation with logrotate

The package installs /etc/logrotate.d/nginx. Logrotate renames the files daily, compresses the old ones, removes the oldest (after 14 rotations on Debian and Ubuntu, 10 on AlmaLinux and Rocky Linux), and then signals Nginx to reopen its logs. Never delete a log that Nginx has open: the disk space is not released, and Nginx keeps writing to the deleted file. If you move a log yourself, run sudo nginx -s reopen afterward. sudo logrotate -d /etc/logrotate.d/nginx shows what the rule would do without changing anything.

Logs Hold Personal Data

IP addresses and user agents count as personal data in many jurisdictions. Keep logs only as long as you need them, set the number of rotations in the logrotate rule to match, and limit who can read them.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations