media-proxy: Use subdomains instead of paths

This should help with isolating the different services.
This commit is contained in:
Simon Bruder 2023-12-16 11:56:04 +01:00
parent 80fcaab244
commit 47998fddd0
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -1,6 +1,5 @@
{ config, lib, pkgs, ... }:
let
port = 8888;
services = {
"media" = config.sops.secrets.media-proxy-auth.path;
"media-sb" = config.sops.secrets.media-proxy-auth.path;
@ -24,37 +23,27 @@ in
enable = true;
commonHttpConfig = ''
map $http_referer $media_proxy_referer {
~^http://localhost:8888/ "";
~^http://.*\.localhost/ "";
default $http_referer;
}
'';
virtualHosts.media-proxy = {
serverName = "localhost";
listen = [
{ inherit port; addr = "127.0.0.1"; }
{ inherit port; addr = "[::1]"; }
];
locations = {
"/".extraConfig = ''
rewrite ^/__nginx-interactive-index-assets__/(.*)$ /media/__nginx-interactive-index-assets__/$1;
'';
} // lib.mapAttrs'
(name: secret: {
name = "/${name}/";
value = {
proxyPass = "https://${name}.sbruder.de/";
proxyWebsockets = true;
extraConfig = ''
proxy_buffering off;
include ${secret};
charset utf-8;
proxy_set_header Referer $media_proxy_referer;
proxy_set_header Origin $media_proxy_referer;
'';
};
})
services;
};
virtualHosts = lib.mapAttrs'
(name: secret: lib.nameValuePair "${name}.localhost" {
locations."/" = {
proxyPass = "https://${name}.sbruder.de/";
proxyWebsockets = true;
# they interfere here, as the host needs to be changed
recommendedProxySettings = false;
extraConfig = ''
proxy_buffering off;
include ${secret};
charset utf-8;
proxy_set_header Referer $media_proxy_referer;
proxy_set_header Origin $media_proxy_referer;
'';
};
})
services;
};
};
}