log_format

nginx服务器日志相关指令主要有两条:

  • log_format:用来设置日志格式;
  • access_log:用来指定日志文件的存放路径、格式和缓存大小;

access_log

Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
access_log off;

Default:
access_log logs/access.log combined;

示例代码1

1
2
3
4
5
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';

access_log /spool/logs/nginx-access.log compression buffer=32k;

log_format main ‘$remote_addr - $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘“$http_user_agent” “$http_x_forwarded_for”‘;