depot/tools/nginx.nix

59 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2021-10-16 18:03:53 +03:00
# internal interface
{ toolsets }:
# external interface
{ config ? null, lib ? null, domain ? toolsets.meta.domain, ... }:
let
tools = (self: {
inherit domain;
mappers = {
2022-03-13 00:16:38 +02:00
mapSubdomains = with lib; mapAttrs' (k: nameValuePair "${k}.${domain}");
2021-10-16 18:03:53 +03:00
};
vhosts = with self.vhosts; {
basic = {
forceSSL = true;
enableACME = true;
};
redirect = target: basic // {
locations."/".return = "301 ${target}";
};
proxy = target: basic // {
locations."/".proxyPass = target;
};
static = root: basic // {
inherit root;
};
indexedStatic = root: (static root) // {
extraConfig = "autoindex on;";
};
simplePHP = root: (static root) // {
locations."~ \.php$".extraConfig = ''
fastcgi_pass unix:${config.services.phpfpm.pools.www.socket};
fastcgi_index index.php;
'';
};
2021-10-16 16:07:53 +03:00
proxyGhost = scheme: target: basic // {
locations."/".extraConfig = ''
proxy_pass ${scheme}://${target};
proxy_set_header Host ${target};
proxy_set_header Referer ${scheme}://${target};
proxy_cookie_domain ${target} domain.invalid;
proxy_set_header Cookie "";
'';
};
2021-10-16 18:03:53 +03:00
};
}) tools;
in tools