trilium-server: Add nginx reverse proxy configuration to module

gstqt5
Christian Kampka 2019-12-06 14:20:39 +01:00
parent 82f038d468
commit 9f97485399
No known key found for this signature in database
GPG Key ID: B88E140DB4FE1AA5
2 changed files with 68 additions and 2 deletions

View File

@ -55,9 +55,36 @@ in
The port number to bind to.
'';
};
nginx = mkOption {
default = {};
description = ''
Configuration for nginx reverse proxy.
'';
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Configure the nginx reverse proxy settings.
'';
};
hostName = mkOption {
type = types.str;
description = ''
The hostname use to setup the virtualhost configuration
'';
};
};
};
};
};
config = lib.mkIf cfg.enable {
config = lib.mkIf cfg.enable (lib.mkMerge [
{
meta.maintainers = with lib.maintainers; [ kampka ];
users.groups.trilium = {};
@ -83,5 +110,28 @@ in
"d ${cfg.dataDir} 0750 trilium trilium - -"
"L+ ${cfg.dataDir}/config.ini - - - - ${configIni}"
];
};
}
(lib.mkIf cfg.nginx.enable {
services.nginx = {
enable = true;
virtualHosts."${cfg.nginx.hostName}" = {
locations."/" = {
proxyPass = "http://${cfg.host}:${toString cfg.port}/";
extraConfig = ''
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
'';
};
extraConfig = ''
client_max_body_size 0;
'';
};
};
})
]);
}

View File

@ -10,6 +10,14 @@ import ./make-test-python.nix ({ ... }: {
dataDir = "/data/trilium";
};
};
nginx = {
services.trilium-server = {
enable = true;
nginx.enable = true;
nginx.hostName = "trilium.example.com";
};
};
};
testScript =
@ -33,5 +41,13 @@ import ./make-test-python.nix ({ ... }: {
with subtest("configured with custom data store"):
configured.wait_for_unit("trilium-server.service")
configured.succeed("test -f /data/trilium/document.db")
with subtest("nginx with custom host name"):
nginx.wait_for_unit("trilium-server.service")
nginx.wait_for_unit("nginx.service")
nginx.succeed(
"curl --resolve 'trilium.example.com:80:127.0.0.1' http://trilium.example.com/"
)
'';
})