美文网首页
【nginx】nignx日志格式解析

【nginx】nignx日志格式解析

作者: Bogon | 来源:发表于2023-07-28 23:55 被阅读0次

    $ cat /usr/local/openresty/nginx/conf/nginx.conf

        log_format main '$remote_addr######-######$remote_user######[$time_local]######"$request"######'
        '$status######$body_bytes_sent######"$http_referer"######'
        '"$http_user_agent"######$request_time######$http_host######$request_id######$upstream_addr######$upstream_status######$http_X_Request_Id######$scheme######$upstream_response_time######$http_x_real_ip######$request_length';
    

    按照 "#####" 分隔符将日志记录分成多列,对每列进行解释说明:

    1. $remote_addr:客户端 IP 地址;
    2. - :保留字段,暂时没使用;
    3. $remote_user:客户端的用户名(如果有);
    4. [$time_local]:请求发生的时间,使用 nginx 默认的时间格式;
    5. "$request":请求的方法、URL 和协议;
    6. $status:HTTP 状态码;
    7. $body_bytes_sent:发送给客户端的数据量;
    8. "$http_referer":HTTP Referer 首部;
    9. "$http_user_agent":HTTP User-Agent 首部;
    10. $request_time:请求处理时间,单位为秒;
    11. $http_host:HTTP Host 首部;
    12. $request_id:自定义的请求 ID;
    13. $upstream_addr:上游服务器的 IP 地址;
    14. $upstream_status:上游服务器返回的 HTTP 状态码;
    15. $http_X_Request_Id:HTTP X-Request-Id 首部;
    16. $scheme:使用的协议;
    17. $upstream_response_time:上游服务器响应时间,单位为秒;
    18. $http_x_real_ip:HTTP X-Real-IP 首部;
    19. $request_length:请求的长度,单位为字节。
    

    该 nginx 配置文件中定义的日志格式中的一个变量,通过 "######" 分隔符连接起来,方便日志分析和排查问题。

    相关文章

      网友评论

          本文标题:【nginx】nignx日志格式解析

          本文链接:https://www.haomeiwen.com/subject/opkljdtx.html