# Nginx access log rotate

# Log raoted policy enforcement

## Final logrotate config for `access.json`

Create / edit:

<div class="contain-inline-size rounded-2xl corner-superellipse/1.1 relative bg-token-sidebar-surface-primary" id="bkmrk-sudo-nano-%2Fetc%2Flogro"><div class="sticky top-[calc(--spacing(9)+var(--header-height))] @w-xl/main:top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">sudo</span> nano /etc/logrotate.d/nginx-access-json`</div></div>Paste **exactly this**:

<div class="contain-inline-size rounded-2xl corner-superellipse/1.1 relative bg-token-sidebar-surface-primary" id="bkmrk-%2Fvar%2Flog%2Fnginx%2Facces"><div class="sticky top-[calc(--spacing(9)+var(--header-height))] @w-xl/main:top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`/var/log/nginx/access.json {    daily    rotate 30    maxsize 30G    missingok    notifempty    compress    delaycompress    dateext    dateformat -%Y%m%d    copytruncate    create 0640 www-data adm}`</div></div>---

## 🔍 What this guarantees

<div class="TyagGW_tableContainer" id="bkmrk-requirement-covered-"><div class="group TyagGW_tableWrapper flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="865" data-start="630"><thead data-end="655" data-start="630"><tr data-end="655" data-start="630"><th data-col-size="sm" data-end="644" data-start="630">Requirement</th><th data-col-size="sm" data-end="655" data-start="644">Covered</th></tr></thead><tbody data-end="865" data-start="679"><tr data-end="697" data-start="679"><td data-col-size="sm" data-end="692" data-start="679">Rotate daily</td><td data-col-size="sm" data-end="697" data-start="692">✅</td></tr><tr data-end="728" data-start="698"><td data-col-size="sm" data-end="711" data-start="698">Keep 30 days</td><td data-col-size="sm" data-end="728" data-start="711">✅ `rotate 30`</td></tr><tr data-end="769" data-start="729"><td data-col-size="sm" data-end="750" data-start="729">Rotate early if huge</td><td data-col-size="sm" data-end="769" data-start="750">✅ `maxsize 30G`</td></tr><tr data-end="806" data-start="770"><td data-col-size="sm" data-end="786" data-start="770">No nginx reload</td><td data-col-size="sm" data-end="806" data-start="786">✅ `copytruncate`</td></tr><tr data-end="826" data-start="807"><td data-col-size="sm" data-end="821" data-start="807">Promtail-safe</td><td data-col-size="sm" data-end="826" data-start="821">✅</td></tr><tr data-end="847" data-start="827"><td data-col-size="sm" data-end="842" data-start="827">Disk protected</td><td data-col-size="sm" data-end="847" data-start="842">✅</td></tr><tr data-end="865" data-start="848"><td data-col-size="sm" data-end="860" data-start="848">JSON intact</td><td data-col-size="sm" data-end="865" data-start="860">✅</td></tr></tbody></table>

</div></div>---

## 🧪 Test immediately (no waiting)

<div class="contain-inline-size rounded-2xl corner-superellipse/1.1 relative bg-token-sidebar-surface-primary" id="bkmrk-sudo-logrotate--d-%2Fe"><div class="sticky top-[calc(--spacing(9)+var(--header-height))] @w-xl/main:top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">sudo</span> logrotate -d /etc/logrotate.d/nginx-access-json`</div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">sudo</span> logrotate -f /etc/logrotate.d/nginx-access-json`</div></div>