nginx日志格式案例

###nginx日志格式案例(一)html

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日志格式案例(二)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

参考1浏览器

相关文章
相关标签/搜索