###nginx日志格式案例(一)
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
- $remote_addr: 客户端IP地址
- $remote_user: 为基本用户认证提供的用户名
- $time_local: 通用日志格式下的本地时间
- $request: 完整的原始请求行(in ngx_http_core_module)
- $status: 响应码
- $body_bytes_sent : nginx返回给客户端的字节数,不含响应头
- $http_referer:
- $http_user_agent: 记录客户端浏览器相关信息
- $http_x_forwarded_for: 获取真实IP地址
【ngx_http_proxy_module中】
$proxy_add_x_forwarded_for
将$remote_addr变量值添加在客户端“X-Forwarded-For”请求头的后面,并以逗号分隔。 如果客户端请求未携带“X-Forwarded-For”请求头,$proxy_add_x_forwarded_for变量值将与$remote_addr变量相同。
###nginx日志格式案例(二)
log_format main '$host ' //“Host”请求头的值,如果没有该请求头,则为与请求对应的虚拟主机的首要主机名
'$server_addr ' //接受请求的服务器地址
'$remote_addr ' //客户端IP地址
'- '
'"$time_local" '
'$status '
'$body_bytes_sent '
'$request_time ' //请求处理的时间,单位为秒,精度是毫秒(1.3.9, 1.2.6);请求处理时间从由客户端接收到第一个字节开始计算
'"$http_referer" ' //告诉服务器我是从哪个页面链接过来的
'"$request" '
'"$http_user_agent" '
'$pid'; //处理请求的nginx进程id