当前位置: 首页 > Linux

Nginx配置访问日志请求日志详解

时间:2023-04-06 11:59:54 Linux

配置示例log_formatmain'$remote_addr-$remote_user[$time_local]''"$request"$status$bytes_sent''"$http_referer""$http_user_agent""$http_x_forwarded_for"';access_loglogs/access.logmain;log_formatdirective默认值:log_format组合“...”;标签段位置:http常用变量:$bytes_sent发送给客户端内容的字节数,位于ngx_http_log_module$request_length请求长度(包括请求行、头部和请求文本),位于ngx_http_log_module$request_time请求处理时间,单位毫秒,在ngx_http_log_module$status状态码,在ngx_http_log_module$time_local请求的本地时间和城市,在ngx_http_log_module$remote_addr客户端地址,在ngx_http_core_module$remote_user基本授权模式下的客户端用户名,位于ngx_http_core_module$request完整的请求地址和协议,位于ngx_http_core_module$request_body请求体内容,位于ngx_http_core_module$http_host域名或IP$http_referer请求重定向源$http_user_agent浏览器信息$http_x_forwarded_for记录客户端地址配置如果变量对应的值不存在,则用“-”代替。access_log命令的默认值:access_loglogs/access.log合并;标签段的location:http,server,location,如果在location,limit_exceptaccess_logoff;access_log日志/access.logmain;access_loglogs/access.logmainbuffer=32kflush=5s;map$status$loggable{~^[23]0;default1;}#非2xx和3xx的状态写入日志access_log/path/to/access.logmainif=$loggable;重新加载配置../sbin/nginx-t../sbin/nginx-sreload参考:http://nginx.org/en/docs/http...http://nginx.org/en/docs/http……