日志格式定义
日志格式需要定义在 http
段中,而不是 server 段中。
log_format main '$remote_addr $remote_port - [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
这个日志格式的名字就叫做 main
。
日志格式的使用
日志使用域可以是 http
、server
、location
access_log /var/log/nginx/access.log main;
这个就是指定使用 main
格式的日志。
参考: - https://www.jianshu.com/p/ad4e8038bf8b - https://blog.51cto.com/john88wang/1672876