1.切换到 logrotate.d目录下
cd /etc/logrotate.d/
2.查看目录是否含有nginx目录,一般yum安装的nginx都会存在,不存在则创建
3.修改nginx内容
/home/wwwlogs/*.log #nginx.conf中access.log记录的目录
{
su root root #对应运行nginx的用户
create 0640 root root
daily #按天切割
rotate 30
missingok
notifempty
nocompress
sharedscripts
postrotate
#/bin/kill -USR1 `cat /usr/local/nginx/logs/nginx.pid 2>/dev/null` 2>/dev/null || true
nginx -s reload >/dev/null 2>&1
endscript
}
4.刷新配置
logrotate -vf nginx
如果出现报错则查看目录是否正确,权限是否正确
成功则目录会新增access.log.1文件,如图
这样就配置完成了