侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

nginx日志格式案例

2023-11-28 星期二 / 0 评论 / 0 点赞 / 56 阅读 / 2052 字

###nginx日志格式案例(一)log_format main '$remote_addr - $remote_user [$time_local] "$request" '

###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

参考1

广告 广告

评论区