Linux下nginx status——nginx访问状态信息

版权声明:本文为博主原创文章,未经博主允许不得转载。原创不易,各位勉之。 https://blog.csdn.net/LL845876425/article/details/81462445

Nginx访问日志(access_log)

Nginx访问日志介绍

Nginx软件会把每个用户访问网站的日志信息记录到指定的日志文件里,供网站提供者分析用户的浏览行为等,此功能由ngx_http_log_module模块负责。对应的官方地址为:http://nginx.org/en/docs/http/ngx_http_log_module.html

访问日志参数

Nginx的访问日志主要由两个参数控制。

Nginx日志格式中默认的参数配置如下:

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

Nginx记录日志的默认参数配置如下:

access_log  logs/access.log  main;

访问日志配置说明

1.日志格式的定义说明
先来看其语法:

定义语法: log_format name string ……;

其配置位置在http标签内。
日志格式说明如下:

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

其中,log_format为日志格式关键参数,不能变。
main是为日志格式指定的标签,记录日志时通过这个main标签选择指定的格式。其后所接的所有内容都是可以记录的日志信息,具体见表5-5。注意,所有的日志段以空格分隔,一行可以记录多个,不同列的意义:

在没有特殊要求的情况下,采用默认的配置即可,更多可以设置的记录日志信息的变量见:
http://nginx.org/en/docs/http/ngx_http_log_module.html

2.记录日志的access_log参数说明
下面是有关access_log参数的官方说明。
语法如下:

access_log path[format[buffer=size[flush=time]][if=condition]];
access_log path format gzip[=level][buffer=size][flush=time][if=condition];
access_log syslog:server=address[,parameter=value][formatif=condition]];

buffer=size为存放访问日志的缓冲区大小,flush=time为将缓冲区的日志刷到磁盘的时间,gzip[=level]表示压缩级别,[if=condition]表示其他条件。一般的场景中,这些参数都无须配置,极端优化时才可能会考虑这些参数。

access_log off中的off,表示不记录访问日志。
默认配置:access_log logs/access.log combined;
放置位置在http、server、location、if in location、limit_except中。

猜你喜欢

转载自blog.csdn.net/LL845876425/article/details/81462445
今日推荐