1.常見默認nginx.conf配置日志格式
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';
(1)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 。
指的就是從接受用戶請求的第一個字節到發送完響應數據的時間,即包括接收請求數據時間、程序響應時間、輸出
響應數據時間。
(2)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向后端(php-cgi)建立連接開始到接受完數據然后關閉連接為止的時間。
從上面的描述可以看出,$request_time肯定比$upstream_response_time值大,特別是使用POST方式傳遞參數時,因為Nginx會把request body緩存住,接受完畢后才會把數據一起發給后端。所以如果用戶網絡較差,或者傳遞數據較大時,$request_time會比$upstream_response_time大很多。