Setting up Goaccess - Pull-Request-Club/PRC GitHub Wiki

  1. Install goaccess

    apt install goaccess
    
  2. Create basic authentication file. Replace $USER with username. Second command will ask you to type password in.

    sudo sh -c "echo -n '$USER:' >> /var/www/html/goaccess/.htpasswd"
    sudo sh -c "openssl passwd -apr1 >> /var/www/html/goaccess/.htpasswd"
    
  1. Add this to /etc/nginx/sites-available/default:

            location ^~ /goaccess/ {
                    try_files $uri $uri/ =404;
                    auth_basic "Restricted area.";
                    auth_basic_user_file /var/www/html/goaccess/.htpasswd;
            }
    
  2. Restart nginx with

    systemctl reload nginx
    
  3. Add following to /etc/goaccess.conf, or alternatively uncomment lines 13, 36 and 64.

    time-format %H:%M:%S
    date-format %d/%b/%Y
    log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
    
  4. Add following root crontab with sudo crontab -e.

    0 * * * * /usr/bin/zcat -f /var/log/nginx/access.log* > /tmp/goaccess-tmp && /usr/bin/goaccess --log-format=COMBINED /tmp/goaccess-tmp > /var/www/html/goaccess/index.html && rm /tmp/goaccess-tmp
    
  5. Optional: Rotate nginx logs more than default of 14:

    perl -p -i -e "s/rotate 14/rotate 30/" /etc/logrotate.d/nginx