最新消息: 新版网站上线了!!!

linux 设置网站日志,每天零时分隔日志

ginx服务器: 
1.修改配置文件nginx.conf,添加log format
 
http
{
    #log format
log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
 
设置网站日志路径:access_log  /opt/site_logs/目录名/access.log  access;
 
2.重启NGINX。
3.设置每天零时切割日志脚本:
crontab -e
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
文件内容:
#!/bin/bash
# This script run at 00:00
 
# The Nginx logs path
logs_path="/opt/site_logs/目录名/"
 
#mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`

转载请注明:谷谷点程序 » linux 设置网站日志,每天零时分隔日志