Using GoAccess to monitor your nginx access log

Suppose you built a Web site, you must be curious at how much traffic your site attract and how do people using it.

You use Nginx as the coordinator server and you know you can analyze its access log.

Analyzing plain text from stratch is hard, and here comes GoAccess, which is amazing.

Here is how it looks.

It’s straight forward to setup GoAccess by following the offical Get Started. I just going through serveral points that you may need to take care.

1. Firstly put the configuration file to the right place

Accordign to the doc

The configuration file is located under ~/.goaccessrc or %sysconfdir%/goaccess.conf where %sysconfdir% is either /etc/, /usr/etc/ or /usr/local/etc/.

It would be a good idea to make changes in the config file, otherwise you have to pass in them everytime your invoke goaccess in command line.

2. You probably need to change the log-format for nginx

If you have several Servers (virtual hosts in Apache) configed in Nginx, you may need to change GoAccess’s default COMBINED log format.

The COMMBINED format is

1
%h %^[%d:%t %^] "%r" %s %b "%R" "%u"

and it does work perfectly with Nginx’s default access log format, which is

1
'$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'

However, as you can see, it doesn’t contain any info for virtual hosts. To make GoAccess analyze virtual host as well, we need to change both Nginx access log format and GoAccess’s log format.

Here is what I did. For backward compatibility, I just switch Nginx’s $remote_user to $host

1
'$remote_addr - $host [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'

and change GoAccess log-format to

1
%h %^ %v [%d:%t %^] "%r" %s %b "%R" "%u"

Please note that while using custom log-format, we need to specify date-format and time-format explict.

That’s all for GoAccess for now.