Nginx log_format性能参数$request_time $upstream_response_time

log_format是指存储日志的时候所采用的格式,可以在/etc/nginx//nginx.conf的http字段中设置

默认配置如下:

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

  access_log  /var/log/nginx/access.log  main;

在分析性能过程,有时需要分析请求耗时,可以添加$request_time $upstream_response_time两个参数实现:

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

    access_log  /var/log/nginx/access.log  main;

完整案例:

复制代码
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

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

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    server_tokens off;
    add_header X-Frame-Options SAMEORIGIN;
    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
复制代码

具体参数解释如下:

 

posted on   uestc2007  阅读(567)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
历史上的今天:
2020-03-18 Fiddler抓包7-post请求(json)
2020-03-18 Fiddler抓包6-get请求(url详解)
2020-03-18 Fiddler抓包5-接口测试(Composer)
2020-03-18 Fiddler抓包4-工具介绍(request和response)
2020-03-18 Fiddler抓包3-查看get与post请求
2020-03-18 Fiddler抓包2-只抓APP的请求
2020-03-18 Fiddler抓包1-抓firefox上https请求

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示