mirror of
https://github.com/archtechx/nix.git
synced 2025-12-12 19:34:04 +00:00
Add realip.nix
This commit is contained in:
parent
bc8ad1fd71
commit
ecf65b125d
2 changed files with 27 additions and 0 deletions
20
realip.nix
Normal file
20
realip.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ pkgs, lib, ... }: {
|
||||
services.nginx.commonHttpConfig =
|
||||
let
|
||||
realIpsFromList = lib.strings.concatMapStringsSep "\n" (x: "set_real_ip_from ${x};");
|
||||
fileToList = x: lib.strings.splitString "\n" (builtins.readFile x);
|
||||
cfipv4 = fileToList (pkgs.fetchurl {
|
||||
url = "https://www.cloudflare.com/ips-v4";
|
||||
sha256 = "0ywy9sg7spafi3gm9q5wb59lbiq0swvf0q3iazl0maq1pj1nsb7h";
|
||||
});
|
||||
cfipv6 = fileToList (pkgs.fetchurl {
|
||||
url = "https://www.cloudflare.com/ips-v6";
|
||||
sha256 = "1ad09hijignj6zlqvdjxv7rjj8567z357zfavv201b9vx3ikk7cy";
|
||||
});
|
||||
in
|
||||
''
|
||||
${realIpsFromList cfipv4}
|
||||
${realIpsFromList cfipv6}
|
||||
real_ip_header CF-Connecting-IP;
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue