Use logrotate to poll nginx and Apache Log document directories [Hide]
- Configure nginx
- Configure Apache
Using logrotate to poll logs is convenient and easy to configure.
Configure nginx
1. Create the/etc/logrotate. d/nginx file.
- VI/etc/logrotate. d/nginx
2. Write the following content:
- /Var/log/nginx/* log {
- Daily
- Rotate 10
- Missingok
- Notifempty
- Compress
- Sharedscripts
- Postrotate
- [! -F/var/run/nginx. pid] | kill-usr1 'cat/var/run/nginx. PID'
- Endscript
- }
Note:
/Var/log/nginx/* log: The Log Path needs to be poll.
Daily: Round Robin every day
Rotate 10: Keep up to 10 scrolling logs
Missingok: If the log is lost, no error is reported to continue rolling the next log.
Receivempty: Do not scroll when the log is empty on the current day
Compress: Old logs are compressed by gzip by default.
/Var/run/nginx. PID: nginx master process PID
Configure Apache
- /Var/log/httpd/* log {
- Missingok
- Notifempty
- Sharedscripts
- Postrotate
- /Sbin/service httpd reload>/dev/null 2>/dev/null | true
- Endscript
- }
For more information, see https://www.centos.bz/2011/12/logrotate-nginx-log/.
Use logrotate to poll nginx and Apache logs