Paste_Image.png
1. 安裝 GoAccess
Mac 下安裝
brew install goaccess
其它平臺可以參考官網上的教程 http://www.goaccess.io/download
2. 配置 goaccessrc
vim ~/.goaccessrc
在 .goaccessrc
添加如下內容
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^ %^ %^[%d:%t %^] "%r" %s %b "%R" "%u" "%D" "%T" %^
$^
表示忽略這個字段
上面的 配置是根據 nginx 里日志的格式來定義的,我 nginx 的日志格式為
'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" '"$http_user_agent" "$request_time" "$upstream_response_time" "$http_x_forwarded_for"'
3. 分析 Nginx 訪問日志
goaccess -q --no-query-string -f www.example.com.access.log -a -p ~/.goaccessrc > report.html
-q --no-query-string
忽略請求的參數部分,再統計接口的訪問量時可以使用這個參數