← Catalog Matrix

Deployment Execution Blueprint

---
title: Managing Nginx Access Logs to Prevent Server Disk Space Bloat
description: An infrastructure configuration guide to customize Nginx log buffers, format logging arrays, and set up automated logrotate rules.
category: Server Configuration
slug: nginx-log-rotation-disk-bloat
keywords: nginx access log too big, disable nginx logging, clear linux log files disk full, change nginx log file path, logrotate configuration tutorial nginx
---

High-traffic websites can quickly run into an infrastructure bottleneck where their server's hard drive space fills up completely (`100% Disk Utilization`). This frequently traces back to Nginx `access.log` and `error.log` files growing unchecked to tens or hundreds of gigabytes, causing databases to crash and application tasks to stall.

By default, Nginx logs every single static asset hit (like images, CSS, and JS file requests) in raw text. This blueprint provides the exact steps to disable logging on static assets, enable high-performance memory buffering, and configure automated system rotations to compress old log data safely.

### Step 1: Disabling Logging for Static Assets and Favicons

To strip out high-frequency background noise from your logs, wrap your static assets inside dedicated location blocks to disable logging entirely:

```nginx
server {
    listen 80;
    server_name howtodocument.com;

    # Prevent favicon requests from bloating error logs
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Turn off tracking for heavy media assets and caching files
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|webp|svg|woff|woff2)$ {
        expires 30d;
        access_log off;
        log_not_found off;
    }
}
```

Step 2: Implementing High-Performance Memory Log Buffering
Instead of forcing Nginx to write to the hard drive on every single click, you can instruct it to cache log entries in memory buffers and write them to disk in efficient single blocks:
```
http {
    # Set up a centralized tracking layout format
    log_format production_optimized '$remote_addr - $remote_user [$time_local] '
                                    '"$request" $status $body_bytes_sent '
                                    '"$http_referer" "$http_user_agent"';

    # Cache log writes in a 512KB memory buffer, flushing it every 5 seconds
    access_log /var/log/nginx/access.log production_optimized buffer=512k flush=5s;
    error_log /var/log/nginx/error.log warn;
}
```
Step 3: Hardening Linux logrotate to Automatically Purge Old Files
Linux systems use a utility called logrotate to supervise background log tracking tasks. Let's configure it to automatically compress old logs and keep a strict 7-day storage limit.

Open or create your custom Nginx rotation policy profile file using your terminal:

```bash
sudo nano /etc/logrotate.d/nginx
```

Paste this production-ready configuration block directly inside the file:
```
/var/log/nginx/*.log {
    daily           # Rotate logs every 24 hours
    missingok       # Do not throw errors if a file is missing
    rotate 7        # Maintain only the last 7 files (deletes file #8 automatically)
    compress        # Compress historical logs into gzip (.gz) format to save 90% space
    delaycompress   # Wait until the next cycle to compress the most recent backup
    notifempty      # Do not cycle empty log tracking sheets
    create 0640 nginx adm # Re-instantiate blank tracking files with secure permission bits
    sharedscripts
    postrotate
        # Signal Nginx to cleanly re-open new log files without a server reboot
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}
```

# Verify configuration flags and force a manual dry-run rotation pass
```bash
sudo logrotate -f /etc/logrotate.d/nginx
```