add traefik for docker routing
This commit is contained in:
parent
aef20d8b6e
commit
c54f44c63c
1 changed files with 67 additions and 38 deletions
|
|
@ -22,8 +22,26 @@
|
|||
"dash" = "https://${homelab.domain}";
|
||||
"immich" = "https://gallery.proxy${homelab.domain}";
|
||||
};
|
||||
exta-conf = ''
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
# proxy_set_header X-Auth-User $remote_user;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_send_timeout 600s;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
send_timeout 600s;
|
||||
client_max_body_size 50000M;
|
||||
'';
|
||||
in {
|
||||
users.users.nginx.extraGroups = [ "acme" ];
|
||||
users.users = {
|
||||
nginx.extraGroups = [ "acme" ];
|
||||
traefik.extraGroups = [ "docker" ];
|
||||
};
|
||||
|
||||
security.acme = {
|
||||
acceptTerms = true;
|
||||
defaults.email = "admin@${homelab.domain}";
|
||||
|
|
@ -36,7 +54,8 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
services = {
|
||||
nginx = {
|
||||
enable = true;
|
||||
recommendedProxySettings = true;
|
||||
recommendedTlsSettings = true;
|
||||
|
|
@ -45,7 +64,14 @@ in {
|
|||
default = true;
|
||||
forceSSL = true;
|
||||
useACMEHost = base;
|
||||
locations."/".return = "404";
|
||||
# locations."/".return = "404";
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:81"; # traefik for docker container dynamic proxy
|
||||
proxyWebsockets = true;
|
||||
extraConfig = ''
|
||||
proxy_set_header Host $host;
|
||||
'' + exta-conf;
|
||||
};
|
||||
};
|
||||
} // lib.mapAttrs' (subdomain: cfg: lib.nameValuePair "${subdomain}.${base}" {
|
||||
useACMEHost = base;
|
||||
|
|
@ -62,21 +88,24 @@ in {
|
|||
proxyPass = cfg.dest;
|
||||
proxyWebsockets = true;
|
||||
basicAuthFile = if cfg.auth then "/var/lib/nginx/.htpasswd" else null;
|
||||
extraConfig = ''
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
# proxy_set_header X-Auth-User $remote_user;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_send_timeout 600s;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
send_timeout 600s;
|
||||
client_max_body_size 50000M;
|
||||
'';
|
||||
extraConfig = exta-conf;
|
||||
};
|
||||
}) hosts;
|
||||
};
|
||||
traefik = {
|
||||
enable = true;
|
||||
staticConfigOptions = {
|
||||
entryPoints.web.address = "127.0.0.1:81";
|
||||
global = {
|
||||
checkNewVersion = false;
|
||||
sendAnonymousUsage = false;
|
||||
};
|
||||
providers.docker = {
|
||||
endpoint = "unix:///var/run/docker.sock";
|
||||
exposedByDefault = false;
|
||||
defaultRule = "Host(`ct-{{ normalize .Name }}.${base}`)";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue