NginX - 響應時間計算與日志輸出格式修改




日志輸出配置

  • 日志輸出

    • 默認調用 combined 格式:

      log_format combined '$remote_addr - $remote_user [$time_local] '
                          '"$request" $status $body_bytes_sent '
                          '"$http_referer" "$http_user_agent" ';
      
    • Nginx 也允許自定義日志格式,例如:

      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"';
      

      輸出日志時,還需明確指定調用自定義格式名(示例中為 main):

      access_log logs/access.log main;
      

時間計算屬性

主要涉及以下兩個屬性值,可根據需要應用計算:

  • request_time

    • 官網描述

      request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client.

    • 應用釋義

      該屬性計算的是從接收到用戶發送請求中的第一個字節發送完完整響應數據的時間;

      可粗略理解為:request_time = 接收請求數據時間 + 后端服務響應時間 + 輸出響應數據時間

  • upstream_response_time

    • 官網描述

      keeps times of responses obtained from upstream servers; times are kept in seconds with a milliseconds resolution. Several response times are separated by commas and colons like addresses in the $upstream_addr variable.

    • 應用釋義

      該屬性計算的是從 Nginx與后端服務建立連接接收完數據關閉連接的時間;

      可粗略理解為: 后端服務響應時間(略去 Nginx 與后端服務之間的數據傳輸時間)

  • time_local

    日志輸出時間



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM