本文将讲述Nginx中如何配置错误和请求处理的日志处理, 以及运行时监控Nginx和Nginx Plus。
error_log logs/error.log warn;
http {
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
server {
gzip on;
access_log /spool/logs/nginx-access.log compression;
...
}
}
access_log /spool/logs/nginx-access.log compression buffer=32k;
1. 下一行日志不适于写入缓冲区。
2. 缓冲区的数据存在时间超过flush参数。
3. worker process重新打开日志文件或被关闭。
# 排除2xx和3xx状态码的请求
map $status $loggable {
~^[23] 0;
default 1;
}
access_log /path/to/access.log combined if=$loggable;
access_log syslog:server=192.168.1.1 debug;
error_log syslog:server=unix:/var/log/nginx.sock;
error_log syslog:server=[2001:db8::1]:12345,facility=local7,tag=nginx,severity=info combined;