nginx默认的日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
字段说明
127.0.0.1 - - [14/May/2017:12:51:13 +0800] "GET /index.html HTTP/1.1" 200 4286 "http://127.0.0.1/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"
远程主机IP 请求时间 时区 方法 资源 协议 状态码 发送字节 referer 浏览器信息
统计访问IP前十
# awk '{print $1}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr | head -10
6958 123.174.51.164
2307 111.85.34.165
1617 118.112.143.148
1489 117.63.146.40
1404 118.182.116.39
1352 1.48.219.30
1132 60.222.231.46
1129 10.35.1.82
943 27.227.163.200
880 58.253.6.133
统计指定某一天的访问IP
# grep "17/May/2017" /usr/local/nginx/logs/access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10
# awk '/17\/May\/2017/{print $1}' /usr/local/nginx/logs/access.log | sort | uniq -c | sort -nr | head -10
6958 123.174.51.164
2307 111.85.34.165
1617 118.112.143.148
1489 117.63.146.40
1404 118.182.116.39
1352 1.48.219.30
1132 60.222.231.46
1129 10.35.1.82
943 27.227.163.200
880 58.253.6.133
本文介绍了如何分析Nginx访问日志,包括理解默认日志格式,统计访问IP前10,查询特定日期的IP,通过grep和awk加速处理大文件,过滤特定URL,统计特定资源,以及筛选指定时间后的日志和计算流量。同时,文章还探讨了如何统计不同HTTP状态码的出现情况。
1529

被折叠的 条评论
为什么被折叠?



