Nginx日志
nginx.conf
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ';
log_format zp '$remote_addr ';
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#引入不同的conf
include /etc/nginx/*.conf;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
}
include /etc/nginx/*.conf; 意义:将每个server用不同的conf文配置,方便业务排查问题以及日志查看
.conf里面是一个个的server
server {
listen 80;
server_name enjoyzp.com;
#charset koi8-r;
access_log logs/host.access.log zp;
location / {
root /etc/nginx/html;
index a.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
error_log
access_log
nginx两种输出日志,打印日志可以方便排查业务中的问题。
nginx日志切割
编写日志切割脚本
#!/bin/bash
#设置日志文件存放目录
LOGS_PATH=/usr/local/nginx/logs
#备分文件名称
YESTERDAY=$(date -d "yesterday" +%Y%m%d%H%M)
#重命名日志文件
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
## 向 Nginx 主进程发送 USR1 信号。USR1 信号是重新打开日志文件
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
2、设置linux定时任务
crontab -e
0 0 * * * root /usr/local/nginx/logs/ngx_log.sh