Skip to content

Copies nginx access log file entries into a sqlite database and optionally adds firewall rules to reject malicious HTTP requests.

Notifications You must be signed in to change notification settings

nylssoft/goaccesslog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goaccesslog

Introduction

Copies nginx access log file entries into a sqlite database and optionally adds firewall rules to reject malicious HTTP requests. The rules used to detect malicious requests can be configured using a simple grammar, see sample.json and rule.go.

Only a fixed nginx access log format is supported. Start the program to see the required log format.

The program is intended to be used on linux servers.

How to build

  • Install the required go version (see go.mod).
  • Set CGO_ENBALED=1 and install gcc (required to build sqlite).
  • go build
  • Example setup for Windows WSL see below

Setup on Windows using WSL

wsl

  • wsl --update
  • wsl --install -d Ubuntu-24.04 --name ubuntu-dev

ubuntu update & upgrade

  • cd
  • sudo apt update
  • sudo apt upgrade

install build essential

  • sudo apt install build-essential

install nginx and adjust logging configuration

Note: no other process should listen on port 80

  • sudo apt install nginx

  • sudo nano /etc/nginx/nginx.conf

    log_format noreferer '$remote_addr - $remote_user [$time_local] $msec "$request" $request_length $status $body_bytes_sent $request_time "$http_user_agent"';

    access_log /var/log/nginx/access.log noreferer;

  • sudo nginx -t

  • sudo nginx -s reload

  • curl localhost

  • sudo cat /var/log/nginx/access.log

install go

download source

build & develop & run

  • export CGO_ENABLED=1
  • go build
  • code .
  • sudo ./goaccesslog -config configs/sample.json
  • sudo cat /var/log/goaccesslog.log

build sqlite

Start new bash

test view access log entries

  • curl localhost
  • wait 1 minute
  • sudo ./sqlite3 ../goaccesslog/goaccesslog.db "select * from accesslog;"

run unit tests and build test coverage

  • go test ./... -coverprofile=cover.out
  • go tool cover -html=cover.out

About

Copies nginx access log file entries into a sqlite database and optionally adds firewall rules to reject malicious HTTP requests.

Resources

Stars

Watchers

Forks

Languages