Last active
August 25, 2017 11:49
-
-
Save bachp/76680d8f1eae76a83016ba47cd50a4c0 to your computer and use it in GitHub Desktop.
load-balancer-mod.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
backend = | |
{ config, pkgs, comment ... }: | |
{ services.httpd.enable = true; | |
services.httpd.adminAddr = "alice@example.org"; | |
services.httpd.documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html"; | |
networking.firewall.allowedTCPPorts = [ 80 ]; | |
}; | |
in | |
{ | |
network.description = "Load balancing network"; | |
proxy = | |
{ config, pkgs, nodes, ... }: | |
{ services.httpd.enable = true; | |
services.httpd.adminAddr = "bob@example.org"; | |
services.httpd.extraModules = ["proxy_balancer" "lbmethod_byrequests"]; | |
services.httpd.extraConfig = | |
'' | |
<Proxy balancer://cluster> | |
Allow from all | |
BalancerMember http://backend1 retry=0 | |
BalancerMember http://backend2 retry=0 | |
</Proxy> | |
ProxyPass / balancer://cluster/ | |
ProxyPassReverse / balancer://cluster/ | |
''; | |
networking.firewall.allowedTCPPorts = [ 80 ]; | |
}; | |
backend1 = backend { comment = "I'm number one"; }; | |
backend2 = backend { comment = "I'm number two"; }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment