kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

nignx log_format 日志常用参数

原始

1
2
3
4
5
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
		  '$status $body_bytes_sent "$http_referer" '
		  '"$http_user_agent" "$http_x_forwarded_for"';

167.94.146.58 - - [09/Nov/2022:05:05:14 +0800] "GET /images/splash/splash-icon.png HTTP/1.1" 404 1163 "-" "Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys.io/)" "-"

改后

1
2
3
4
log_format  main  '$time_local $server_addr $server_port $remote_addr $remote_port $status $body_bytes_sent - $remote_user '
		  '"$host" "$request" "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';

10/Nov/2022:10:32:58 +0800 192.168.100.41 49090 192.168.120.177 65123 404 1163 - - "192.168.100.41" "GET /images/splash/splash-icon.png HTTP/1.1" "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0" "-"

再改后

1
2
3
4
log_format  main  '$time_local $request_time $server_addr $server_port $remote_addr $remote_port $status $body_bytes_sent $request_method $server_protocol'
		  ' "$host" "$uri" "$query_string" "$http_referer" "$http_user_agent" "$http_x_forwarded_for" - $remote_user';

20/Nov/2022:13:19:17 +0800 0.001 192.168.100.41 49090 183.136.225.45 58722 404 1163 GET HTTP/1.1 "np.cn" "/favicon.ico" "-" "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE" "-" - -

再改时间格式、ssl

1
2
3
4
5
6
7
8
9
10
11
12
13
log_format  main  '$fmt_localtime $request_time $server_addr $server_port $remote_addr $remote_port $status $body_bytes_sent $request_method $server_protocol'
		  ' "$host" "$uri" "$query_string" "$http_referer" "$http_user_agent" "$ssl_protocol" "$ssl_cipher" "-" "$remote_user" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

map $host $fmt_localtime {
	default '';
}
log_by_lua_block {
	ngx.var.fmt_localtime = ngx.localtime();
}

2022-11-25 17:15:07 0.046 192.168.100.141 17883 223.104.49.27 12492 200 3371 GET HTTP/1.1 "www.np.cn" "/login" "-" "-" "Mozilla/5.0 (Android 7.0; Mobile; rv:104.0) Gecko/104.0 Firefox/104.0" "TLSv1.2" "ECDHE-RSA-AES128-GCM-SHA256" "-" "-" "-"

https://www.cnblogs.com/funcquery/p/16026830.html

https://www.88ksk.cn/blog/145.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$remote_addr:记录访问网站的客户端地址
$remote_user:远程客户端用户名称
$time_local:记录访问时间与时区
$request:表示request请求头的行
$status:http状态码,记录请求返回的状态,例如:200、404、301等
$body_bytes_sent:服务器发送给客户端的响应body字节数
$http_referer:记录此次请求是从哪个链接访问过来的,可以根据refer进行防盗链设置
$http_user_agent:记录客户端访问信息,例如:浏览器,手机客户端等
$http_x_forwarded_for:当前端有代理服务器时,设置Web节点记录客户端地址的配置,此参数生效的前提是代理服务器上也进行了相关的http_x_forwarded_for设置
$ssl_protocol:SSL协议版本
$ssl_cipher:交换数据中的算法
$upstream_status:upstream状态
$upstream_addr:当ngnix做负载均衡时,可以查看后台提供真实服务的设备
$upstream_response_time:请求过程中,upstream响应时间
$request_time:整个请求的总时间
$args:这个变量等于请求行中的参数,同$query_string
$content_length:请求头中的Content-length字段。
$content_type:请求头中的Content-Type字段。
$document_root:当前请求在root指令中指定的值。
$host:请求主机头字段,否则为服务器名称。
$http_user_agent:客户端agent信息
$http_cookie:客户端cookie信息
$limit_rate:这个变量可以限制连接速率。
$request_method:客户端请求的动作,通常为GET或POST。
$remote_addr:客户端的IP地址。
$remote_port:客户端的端口。
$remote_user:已经经过Auth Basic Module验证的用户名。
$request_filename:当前请求的文件路径,由root或alias指令与URI请求生成。
$scheme:HTTP方法(如http,https)。
$server_protocol:请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
$server_addr:服务器地址,在完成一次系统调用后可以确定这个值。
$server_name:服务器名称。
$server_port:请求到达服务器的端口号。
$request_uri:包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。
$uri:不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。
$document_uri:与$uri相同。