trilium-server: Add nginx reverse proxy configuration to module
This commit is contained in:
parent
82f038d468
commit
9f97485399
2 changed files with 68 additions and 2 deletions
|
@ -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;
|
||||
'';
|
||||
};
|
||||
};
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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/"
|
||||
)
|
||||
'';
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue