nginx日志类型有两种,第一种是error.log
日志,第二种是access_log
日志。error.log是记录错误,access_log用来指定日志文件的存放路径、格式(把定义的log_format 跟在后面)和缓存大小;如果不想启用日志则access_log off ;
1.log_format配置语法
作用:用来设置日志格式
语法:
syntax: log_format name [escape=default | json] string ...;
default: log_format combined "...";
context: http
2.nginx变量
1.http请求变量
log_format main '$http_user_agent $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;