2024-04-12 15:35:56 +00:00
|
|
|
{ stdenv, lib, pkgs, ... }:
|
2024-04-13 13:38:30 +00:00
|
|
|
|
2024-04-12 15:35:56 +00:00
|
|
|
let
|
2024-04-13 13:38:30 +00:00
|
|
|
domain = "metrics.gchq.icu";
|
2024-04-12 15:35:56 +00:00
|
|
|
in
|
|
|
|
{
|
2024-04-13 13:38:30 +00:00
|
|
|
users.users.goaccess = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "nginx";
|
|
|
|
createHome = true;
|
|
|
|
home = "/var/www/goaccess";
|
|
|
|
homeMode = "0774";
|
|
|
|
};
|
2024-04-12 15:35:56 +00:00
|
|
|
|
|
|
|
services.nginx.commonHttpConfig = ''
|
|
|
|
log_format vcombined '$host:$server_port $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referrer" "$http_user_agent"';
|
|
|
|
access_log /var/log/nginx/private.log vcombined;
|
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.services.goaccess = {
|
|
|
|
description = "GoAccess server monitoring";
|
|
|
|
serviceConfig = {
|
2024-04-13 13:38:30 +00:00
|
|
|
User = "goaccess";
|
|
|
|
Group = "nginx";
|
2024-04-12 15:35:56 +00:00
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.goaccess}/bin/goaccess \
|
|
|
|
-f /var/log/nginx/public.log \
|
|
|
|
--log-format=VCOMBINED \
|
|
|
|
--real-time-html \
|
|
|
|
--html-refresh=30 \
|
|
|
|
--no-query-string \
|
|
|
|
--anonymize-ip \
|
|
|
|
--ignore-panel=HOSTS \
|
2024-04-13 13:38:30 +00:00
|
|
|
--ws-url=wss://${domain}:443/ws \
|
2024-04-12 15:35:56 +00:00
|
|
|
--port=7890 \
|
2024-04-13 13:38:30 +00:00
|
|
|
-o index.html
|
2024-04-12 15:35:56 +00:00
|
|
|
'';
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
Type = "simple";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
|
|
|
|
|
|
|
# hardening
|
2024-04-13 13:38:30 +00:00
|
|
|
WorkingDirectory = "/var/www/goaccess";
|
2024-04-12 15:35:56 +00:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectHome = "read-only";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @memlock @module @mount @obsolete @privileged @reboot @resources @setuid @swap @raw-io";
|
|
|
|
ReadOnlyPaths = "/";
|
|
|
|
ReadWritePaths = [ "/proc/self" "/var/www/goaccess" ];
|
|
|
|
PrivateDevices = "yes";
|
|
|
|
ProtectKernelModules = "yes";
|
|
|
|
ProtectKernelTunables = "yes";
|
|
|
|
};
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
|
2024-04-13 13:38:30 +00:00
|
|
|
|
|
|
|
services.nginx.virtualHosts."${domain}" = {
|
2024-04-12 15:35:56 +00:00
|
|
|
addSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
root = "/var/www/goaccess";
|
|
|
|
|
|
|
|
locations."/ws" = {
|
|
|
|
proxyPass = "http://127.0.0.1:7890";
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
proxy_set_header Connection $connection_upgrade;
|
|
|
|
proxy_buffering off;
|
|
|
|
proxy_read_timeout 7d;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|