nginx配置log_format
  YQBUvtbFE7rq 2023年11月02日 54 0

1. 默认格式:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

(1). 参数说明:

|参数|说明| |---|---|---| |nginx配置log_format_客户端remote_user | 客户端用户名称 | -- |nginx配置log_format_客户端_02request | 请求的URI和HTTP协议 | "GET /article-10000.html HTTP/1.1" |nginx配置log_format_Nginx_03body_bytes_sent | 发送给客户端文件内容大小 | 1547 |nginx配置log_format_nginx_04http_user_agent | 用户终端浏览器等信息 | "Mozilla/4.0 ... |$request_time | 整个请求的总时间 | 0.205

2. 自定义log_format:

(1). 自定义log_format:

vim /etc/nginx/nginx.conf
http
{
    ...

    log_format request '$remote_addr - $remote_user [$time_local] "$request"'
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for" $request_time';

    ...
}

(2). 给web网站分配log_format:

server
{
    ...
    access_log  /etc/logs/xxx.log request;
    error_log  /etc/logs/xxx.error.log;
    # 不指定log_format,则使用的默认的log_format.
}

(3). 两个时间的疑问?

  • $request_time: a. request processing time in seconds with a milliseconds resolution(1.3.9, 1.2.6);time elapsed since the first bytes were read from the client. b. 这个时间是从Nginx接收到客户端第一个字节的数据开始计时的,包含了接收数据、等待响应的时间.
  • $upstream_response_time: a. keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable. b. 这个时间是Nginx等待后端程序响应的时间.
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
YQBUvtbFE7rq