使用GoAccess分析Nginx的Virtual Host日志记录

背景

本身的机器上使用的Nginx,并配置了多个Virtual Host。如今须要经过GoAccess分析本身的访问日志。nginx

配置

GoAccess安装

因为是CentOS的主机,直接yum安装:spa

yum install goaccess

若是你是其余机器,能够参考:https://goaccess.io/downloadrest

Nginx配置

默认的Nginxlog_format是不包含Virtual Host的信息的,能够修改/etc/nginx/nginx.conf文件来统计相关信息:日志

log_format vhosts '$host $remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
                      
    access_log  /var/log/nginx/access.log  vhosts;

配置好后,记得启用新的配置:code

sudo service nginx restart

GoAccess配置

修改GoAccess的配置文件:/etc/goaccess.conf,激活以下配置:orm

time-format %H:%M:%S
date-format %d/%b/%Y
log-format %v %h %^[%d:%t %^] "%r" %s %b "%R" "%u" "%^"

使用

个人access.log文件在/var/log/nginx/access.log下,使用GoAccess统计:rem

sudo goaccess -f /var/log/nginx/access.log

效果以下:
GoAccess统计效果get

做者

郭一实 / http://sjz.ioit

相关文章
相关标签/搜索