一、配置日志切割
[root@localhost ~]# vim /usr/local/nginx/conf/cut_nginx_log.sh
#!/bin/bash
cd /usr/local/nginx/logs
/bin/mv access.log access_$(date +%F -d -1day).log # 将日志按日期改成前一天的名称
/usr/local/nginx/sbin/nginx -s reload
[root@localhost ~]# crontab -e # 每天凌晨0点执行脚本 0 0 * * * /bin/sh /usr/local/nginx/conf/cut_nginx_log.sh > /dev/null 2>&1
二、不记录不需要的访问日志
location ~ .*\.(js|jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF)$ {
access_log off;
}
三、设置访问日志的权限
chown -R root.root /usr/local/nginx/logs chmod -R 700 /usr/local/nginx/logs