Skip to content

Commit

Permalink
feat: add misc reverse proxy to bro
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia committed Apr 30, 2024
1 parent 2d938d1 commit f46cede
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions hosts/bro/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
(inputs.nixpkgs-unstable + "/nixos/modules/services/misc/cfdyndns.nix")
]
++ (with profiles; [
caddy.rproxy
services.ssh
]);

Expand Down
31 changes: 31 additions & 0 deletions profiles/caddy/rproxy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Reverse proxy of local ports for misc use, which require a public IP
# and/or HTTPS (i.e. proxying from a laptop using SSH)
{lib, ...}: let
inherit (builtins) attrNames listToAttrs;
inherit (lib) mapAttrs' nameValuePair pipe;

ports = {
"0" = 44380;
"1" = 44381;
"2" = 44382;
};

domainSuffix = ".rproxy.diogotc.com";
in {
security.acme.certs = pipe ports [
attrNames
(map (name: nameValuePair "${name}${domainSuffix}" {}))
listToAttrs
];

services.caddy.virtualHosts =
mapAttrs'
(name: port:
nameValuePair "${name}${domainSuffix}" {
useACMEHost = "${name}${domainSuffix}";
extraConfig = ''
reverse_proxy localhost:${toString port}
'';
})
ports;
}

0 comments on commit f46cede

Please sign in to comment.