前言
- nginx1.15
log_format 中的变量
$scheme
:请求的协议,比如http
、https
;
$host
:请求的地址(IP或域名),比如127.0.0.1
、localhost
、baidu.com
、www.baidu.com
;
$server_port
:请求的端口,比如80
、443
、8080
,
$remote_addr
:客户端的ip地址;
$remote_user
:记录客户端用户的名称;
$time_local
:访问时间及时区;
$request
:请求的URL与HTTP协议,比如GET /index HTTP/1.0
;
$status
:记录请求状态,比如200
、404
;
$body_bytes_sent
:记录发送给客户端文件主体内容大小;
$bytes_sent
:客户端发送的字节数
$request_length
:客户端请求的长度
$upstream_status
:upstream状态
$upstream_addr
:后台upstream的地址,即真正提供服务的主机地址
$request_time
: 整个请求的总时间
$upstream_response_time
:请求过程中,upstream响应时间
$request_body
:POST数据
$http_NAME
:匹配任意请求头字段,NAME可以替换成任意请求头字段。比如$http_accept_language
获取http请求头Accept-Language
;
$http_host
:请求的地址(IP或域名),如果http协议头
包含host
,则对应http协议头
的host
,否则同$host
;
$http_referer
:用来记录从哪个页面链接访问过来的,对应http协议头
的referer
;
$http_user_agent
:记录客户端浏览器的相关信息,对应http协议头
的user-agent
(规律:横线变成下划线了);
$http_x_forwarded_for
: 对应http协议头
的x-forwarded-for
,含义同$remote_addr
,用于反向代理时告知应用客户端的实际IP;
$http_x_forwarded_proto
: 对应http协议头
的x-forwarded-proto
,含义同$scheme
,用于反向代理时告知应用客户端的实际请求协议;
$http_cookie
: 全部的cookie;
$sent_http_NAME
:http响应头字段,NAME可以替换成任意响应头字段。如$sent_http_content_length
获取响应头Content-length
;
$sent_http_cache_control
:
$sent_http_connection
:
$sent_http_content_type
:
$sent_http_keep_alive
:
$sent_http_last_modified
:
$sent_http_location
:
$sent_http_transfer_encoding
:
$cookie_NAME
:客户端请求Header头中的cookie变量,NAME可以替换成任意cookie名称。比如$cookie_jsessionid
获取cookie中的jsessionid
;
参考
http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
https://www.cnblogs.com/luoyan01/p/9734149.html