{ config, ... }: {
  services.prometheus.exporters.nginxlog = {
    enable = true;
    port = 14201;
    user = config.services.nginx.user;
    group = config.services.nginx.group;
    settings = {
      namespaces = [{
        name = "nginx";
        format = ''$server_name: $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'';
        source.files = ["/var/log/nginx/access.log"];
        relabel_configs = [
          { target_label = "host"; from = "server_name"; }
        ];
      }];
    };
  };

  services.nginx.commonHttpConfig = ''
    log_format combined2 "$server_name: $remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\"";
    access_log /var/log/nginx/access.log combined2;
  '';

  networking.firewall.allowedTCPPorts = [ 14201 ];
}
