2021-01-31 16:37:58 +01:00
|
|
|
# Configuration shamelessly stolen from [1]
|
|
|
|
#
|
|
|
|
# [1]: https://github.com/delroth/infra.delroth.net/blob/master/common/nginx.nix
|
2021-07-13 19:10:17 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2021-01-31 16:37:58 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
# Whenever something defines an nginx vhost, ensure that nginx defaults are
|
|
|
|
# properly set.
|
|
|
|
config = lib.mkIf ((builtins.attrNames config.services.nginx.virtualHosts) != [ ]) {
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
statusPage = true; # For monitoring scraping.
|
|
|
|
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
|
|
|
|
# Nginx needs to be able to read the certificates
|
|
|
|
users.users.nginx.extraGroups = [ "acme" ];
|
|
|
|
|
|
|
|
# Use DNS wildcard certificate
|
|
|
|
security.acme = {
|
|
|
|
email = "bruno.acme@belanyi.fr";
|
|
|
|
acceptTerms = true;
|
|
|
|
certs =
|
|
|
|
let
|
|
|
|
domain = config.networking.domain;
|
2021-02-06 13:02:27 +01:00
|
|
|
key = config.my.secrets.acme.key;
|
2021-01-31 16:37:58 +01:00
|
|
|
in
|
2021-02-06 13:02:27 +01:00
|
|
|
with pkgs;
|
2021-01-31 16:37:58 +01:00
|
|
|
{
|
|
|
|
"${domain}" = {
|
|
|
|
extraDomainNames = [ "*.${domain}" ];
|
|
|
|
dnsProvider = "gandiv5";
|
2021-02-06 13:02:27 +01:00
|
|
|
credentialsFile = writeText "key.env" key; # Unsecure, I don't care.
|
2021-01-31 16:37:58 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-07-13 19:10:17 +02:00
|
|
|
# Setup monitoring
|
|
|
|
services.grafana.provision.dashboards = [
|
|
|
|
{
|
|
|
|
name = "NGINX";
|
2021-07-29 13:17:42 +02:00
|
|
|
options.path = pkgs.nur.repos.alarsyo.grafanaDashboards.nginx;
|
2021-07-13 19:10:17 +02:00
|
|
|
disableDeletion = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
services.prometheus = {
|
|
|
|
exporters.nginx = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
};
|
|
|
|
|
|
|
|
scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = "nginx";
|
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.nginx.port}" ];
|
|
|
|
labels = {
|
|
|
|
instance = config.networking.hostName;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2021-01-31 16:37:58 +01:00
|
|
|
};
|
|
|
|
}
|