Back to BlogServers

Log Rotation for Nginx and Journald on Ubuntu

Keep disk usage stable with logrotate, journald limits, and centralized shipping options.

Why rotation matters

Unbounded logs fill disks and cause outages worse than the bugs you were trying to trace. Nginx access logs on busy sites grow quickly.

Vcom Web Tech sets rotation policies before launch, not after the first disk alert.

Retention should meet compliance without hoarding forever.

logrotate for Nginx

Ubuntu packages include logrotate configs for Nginx with daily or weekly rotation and compress delay. Verify postrotate scripts invoke nginx -s reopen so files handle correctly.

Ship logs off-host if you need longer retention than local disk allows.

Separate audit logs with stricter permissions when regulations apply.

journald tuning

Set SystemMaxUse and MaxRetentionSec in journald.conf to cap systemd journal size.

Application logs in journald complement but do not replace structured app logging.

Forward critical unit logs to monitoring when operators live in journalctl during incidents.

Centralization

Loki, ELK, or cloud logging stacks aggregate logs across servers. Tag with hostname and environment.

Parse Nginx logs into fields for useful dashboards on status codes and latency.

Test that rotation still works when agents hold file handles open.

Additional operational notes

Operational excellence on Linux hosting requires documenting every change to Nginx, systemd, PM2, Docker, and DNS in a runbook your team shares. Vcom Web Tech clients benefit when staging environments mirror production firewall rules, TLS versions, and mail authentication so surprises appear before customers notice. Schedule quarterly reviews of backups, certificate expiry, DMARC reports, and monitoring alerts even when traffic feels stable.

When incidents occur, capture timelines and root causes in blameless postmortems. Patterns from past 502 errors, failed renewals, or bounce spikes inform checklists for the next deployment. Training new team members on SSH access, log locations, and escalation paths reduces dependency on single maintainers.

Security patches, dependency upgrades, and framework migrations should ride the same CI pipelines that deploy application code. Automate smoke tests that hit health endpoints and send test mail through staging SMTP relays. Small consistent investments beat heroic firefighting during launch weekends.

Capacity planning matters on VPS hosts where vertical scaling has limits. Watch disk inode usage, connection counts, and database connection pools as traffic grows. Proactive upgrades cost less than emergency migrations during peak sales or campaign sends.

Finally, communicate with stakeholders using plain language about risk, downtime windows, and deliverability metrics. Technical depth supports trust when email authentication or deployment strategy changes affect revenue-facing systems.

Additional operational notes

Operational excellence on Linux hosting requires documenting every change to Nginx, systemd, PM2, Docker, and DNS in a runbook your team shares. Vcom Web Tech clients benefit when staging environments mirror production firewall rules, TLS versions, and mail authentication so surprises appear before customers notice. Schedule quarterly reviews of backups, certificate expiry, DMARC reports, and monitoring alerts even when traffic feels stable.

When incidents occur, capture timelines and root causes in blameless postmortems. Patterns from past 502 errors, failed renewals, or bounce spikes inform checklists for the next deployment. Training new team members on SSH access, log locations, and escalation paths reduces dependency on single maintainers.

Security patches, dependency upgrades, and framework migrations should ride the same CI pipelines that deploy application code. Automate smoke tests that hit health endpoints and send test mail through staging SMTP relays. Small consistent investments beat heroic firefighting during launch weekends.

Capacity planning matters on VPS hosts where vertical scaling has limits. Watch disk inode usage, connection counts, and database connection pools as traffic grows. Proactive upgrades cost less than emergency migrations during peak sales or campaign sends.

Finally, communicate with stakeholders using plain language about risk, downtime windows, and deliverability metrics. Technical depth supports trust when email authentication or deployment strategy changes affect revenue-facing systems.