Skip to content

71 Nginx Log

Jinxin Chen edited this page Dec 11, 2019 · 1 revision

有时候为了找出某些响应时间较长的请求,可以添加 $upstream_response_time - $request_time 这两个参数。

$request_time和$upstream_response_time之间差别: $request_time包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time 所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多

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

可以配合buffer参数来提升性能: When buffering is enabled, the data will be written to the file:

if the next log line does not fit into the buffer; if the buffered data is older than specified by the flush parameter (1.3.10, 1.2.7); when a worker process is re-opening log files or is shutting down.

Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]]; access_log off; Default: access_log logs/access.log combined; Context: http, server, location, if in location, limit_except

#参考:

http://nginx.org/en/docs/http/ngx_http_log_module.html

Clone this wiki locally