Nginx log 分析

Tags
bash
Created
Jun 27, 2021 3:48 PM

https://goaccess.io/faq#configuration

goaccess access.log -o /var/www/html/report.html --log-format=COMBINED --real-time-html --ws-url=wss://tld.com:443/ws

log file size limit: https://serverfault.com/questions/427144/how-to-limit-nginx-access-log-file-size-and-compress

https://wangchujiang.com/linux-command/c/logrotate.html

#统计 IP 数目
awk '{print $1}' access.log | sort -n | uniq | wc -l
# 统计某个时间段的 IP 数目
grep "07/Apr/2017:0[4-5]" access.log | awk '{print $1}' | sort | uniq -c| sort -nr | wc -l
# 访问最平凡的 100 个 url
awk '{print $7}' access.log | sort |uniq -c | sort -rn | head -n 100
# 每分钟请求数
awk '{print $4}' access.log | cut -c 14-18 | sort | uniq -c | sort -nr | head -n 100
# 禁止特定 UA 访问
if ($http_user_agent ~ "Lua"){
     return 403;
}
SuperMade with Super