• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Install GoAccess Nginx Access Log Analyzer on Ubuntu 16.04 PHP 7

By Abhishek Ghosh October 19, 2016 11:18 am Updated on October 19, 2016

Install GoAccess Nginx Access Log Analyzer on Ubuntu 16.04 PHP 7

Advertisement

Previously we talked about configuring GeoIP module for Nginx Access log. This guide can be used on live production server. GoAccess is Easy to Install, Output Available on CLI or As HTML Here is How to Install GoAccess Nginx Access Log Analyzer on Ubuntu 16.04. There are two ways to install GoAccess — we can install from their repository with aptitude package manager or can build from source code with extra completion options. This is their official website. They have live demo :

Vim
1
https://goaccess.io

We will take it granted that your these are your LEMP configuration files (default locations for Ubuntu) :

Vim
1
2
3
4
Nginx log file : /var/log/nginx/access.log
Public root : /usr/share/nginx/html
Nginx sites config file : /etc/nginx/sites-available/default
Others : Does not matter

You need to understand if things differ.

Advertisement

---

 

How to Install GoAccess Nginx Access Log Analyzer on Ubuntu 16.04

 

As like we said above,  we can install from their repository with aptitude package manager or can build from source code with extra completion options. If you just want to test or you are not used with building software from source code, you can install from their repository with aptitude package manager. This way is very easy to uninstall. The disadvantage is that, this way will not give the version with all build options. There are two versions of packages. One not built with --enable-tcb=btree (which needs the command apt install goaccess), to have no on-disk support. For Ubuntu 16.04, we can use the version with built with --enable-tcb=btree (which needs the command apt install goaccess-tcb). We will show the installation of goaccess-tcb.

First add the repository, update :

Vim
1
2
3
echo "deb http://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/goaccess.list
wget -O - https://deb.goaccess.io/gnugpg.key | sudo apt-key add -
apt update

Install needed dependencies for GoAccess :

Vim
1
apt install libnginx-mod-http-perl

It will give many a times prompt to change or keep php.ini, nginx.conf etc files. You will always select the option keep your currently-installed version on production server. These are century old packages for Nginx, PHP 7.x. Any error message is misleading. Actually JSON function loaded differently now. Install another such package :

Vim
1
apt install libtokyocabinet9 libncursesw5-dev libgeoip-dev libtokyocabinet-dev

Finally install GoAccess :

Vim
1
apt install goaccess-tcb

Invoke goaccess by this command :

Vim
1
goaccess -f /var/log/nginx/access.log -a

Install GoAccess Nginx Access Log Analyzer on Ubuntu 16-04 PHP 7

Automatic install is not 100% easy. Otherwise we would not write guide. If you get a blank prompt for setup, simply keep first option, then hit c and fill the first field as %T and hit Enter key. It is useless function at this moment. We need to edit the default config file :

Vim
1
nano /etc/goaccess.conf

Find these lines, they should look active like this (not commented out), edit and save :

/etc/goaccess.conf
Vim
1
2
3
4
...
date-format %d/%b/%Y
...
log-format %h %^[%d:%^] "%r" %s %b "%R" "%u"

 

How to Configure GoAccess HTML GUI Dashboard For Nginx on Ubuntu 16.04, PHP 7

 

If upgraded from Ubuntu 14.04 to Ubuntu 16.04 then root il be at /usr/share/nginx/html. Adjust that part. Now, generate HTML file while being there with this command :

Vim
1
goaccess -f /var/log/nginx/access.log -a > /usr/share/nginx/html/report.html

Check with ls :

Vim
1
ls /usr/share/nginx/html/report.html | grep report

It show the HTML file. Now, open your browser to point towards :

Vim
1
2
3
your-domain.com/report.html
or
your-ip/report.html

You will see the Dashboard. Official documentation is on their website about how to use. As we need to update it continuously, we can use this command to create a goaccess.sh script, invoke to copy-paste these with nano ~/goaccess.sh :

location ~/goaccess.sh
Vim
1
2
3
4
#!/bin/sh
rm /usr/share/nginx/html/report.html
goaccess -f /var/log/nginx/access.log -a > /usr/share/nginx/html/report.html
echo -e "[goaccess.sh ran"

There is no typographical error on the above script. We need to properly CHMOD it :

location ~
Vim
1
chmod +x ~/goaccess.sh

Then test run the script :

location ~
Vim
1
sh ~/goaccess.sh

 

Automation With CRON

 

Now you can set cron, for example, if you want to run the script every 12 hourly, then evoke crontab with crontab -e command and add this at the bottom of the file :

regular usage
Vim
1
55 5,17 * * * sh ~/goaccess.sh > /dev/null 2>&1

If you want to run the script (and update the report) every 10 minutes, evoke crontab with crontab -e command and add this at the bottom of the file :

debugging
Vim
1
*/10 * * * * sh ~/goaccess.sh > /dev/null 2>&1

You can see the “log” of whether ran with this command :

Vim
1
grep goaccess /var/log/syslog

This part is complete. It is not a sane idea to keep an HTML file available publicly on a live website. Also such cron can suck huge RAM. In case you keep it, add this to your /etc/nginx/sites-available/default (or whatever named) file :

Vim
1
2
3
4
5
6
location ~ /(\.|wp-config.php|readme.html|license.txt|report.html)
{
        allow 127.0.0.1;
        allow 27.63.170.224;
        deny all;
}

license.txt, wp-config.php are just added for example in case you have such directive to block access to certain files. My IP is 27.63.170.224. I can access it but others can not see. To make 100% sure, I can check that file from Tor browser (My IP will change).

You should not use crontab for production server when you are not on SSH. Simply delete report.html with :

Vim
1
rm /usr/share/nginx/html/report.html

if exiting from SSH, simply comment out the above used cron with # before the line after opening crontab with crontab -e command. For full managed servers, you can keep the file. Actually there is remote possibility of running exploit and get cron’s access by the script kiddies. We made alternative easy ways (see later part of the guide).

 

Advanced Setup For GoAccess HTML GUI Dashboard (Includes Security)

 

Second part is creating bash alias. Open :

Vim
1
nano ~/.bash_aliases

Copy-Paste :

Vim
1
2
3
alias gostat='goaccess -f /var/log/nginx/access.log -a'
alias gogen='sh ~/goaccess.sh'
alias godel='rm /usr/share/nginx/html/report.html'

Source bash profile :

Vim
1
source ~/.bashrc

Type gostat and hit ENTER key to test. Q is exit.
We kept gogen command for generating new HTML report file. godel command will delete HTML report file. You can run gogen command after login to SSH, check HTML report and run godel before exiting SSH. You can forget that you have GoAccess in the context of security.

Tagged With configuring goaccess conf , nginx log analysis , paperuri:(32e01eefab1bed661bf65bfaacbe0366) , ubuntu 16 04 apache access log syslog config , ubuntu loganalyzer php 7
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Install GoAccess Nginx Access Log Analyzer on Ubuntu 16.04 PHP 7

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Install GoAccess Real-Time Web Log Analyzer : Apache, Ubuntu

    Here Is How To Install GoAccess Real-Time Web Log Analyzer For Apache WebServer Running On Ubuntu. We Have Shown With GeoIP Enabled Features.

  • How to Install WordPress : Ubuntu 16.04, Nginx, PHP7-FPM

    Here is Step by Step Guide on How to Install WordPress on Ubuntu 16.04, Nginx, PHP7-FPM, memcached & Percona MySQL 5.7 on Cloud Server or VPS.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy