Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean /var/log/nginx logs file

Tags:

logging

nginx

I have over 10.0G logs under /var/log and /var/log/nginx. How can I safely clean it?

7.8G /var/log/nginx/custom 2.0G /var/log/nginx 2.0G /var/log

like image 901
angelokh Avatar asked Sep 05 '15 06:09

angelokh


1 Answers

To control application's lifecycle Unix provides a mechanism called Unix signals. USR1 is custom and usually handles the log rotation, other signal like HUP is standard and performs reload.

http://nginx.org/en/docs/control.html

TERM, INT   fast shutdown
QUIT    graceful shutdown
HUP changing configuration, keeping up with a changed time zone (only for FreeBSD and Linux), starting new worker processes with a new configuration, graceful shutdown of old worker processes
USR1    re-opening log files
USR2    upgrading an executable file
WINCH   graceful shutdown of worker processes

Before send a signal to PID rename the file. After you rename it log entries will still be going into the same file because inode hasn't been changed.

cd /var/log/nginx
mv access.log access.log.old
mv error.log error.log.old
kill -USR1 `cat /var/run/nginx.pid`
like image 150
Anatoly Avatar answered Sep 21 '22 08:09

Anatoly