mirror of
https://github.com/archtechx/nix.git
synced 2025-12-12 11:24:04 +00:00
Add realip.nix
This commit is contained in:
parent
bc8ad1fd71
commit
ecf65b125d
2 changed files with 27 additions and 0 deletions
|
|
@ -269,6 +269,13 @@ However a more proper solution is to use the `real_ip` module in common nginx co
|
|||
we can follow the [guide from the NixOS
|
||||
wiki](https://nixos.wiki/wiki/Nginx#Using_realIP_when_behind_CloudFlare_or_other_CDN).
|
||||
|
||||
> [!NOTE]
|
||||
> You can also use the `realip.nix` module here (which wraps the code below):
|
||||
>
|
||||
> `scp realip.nix root@<server ip>:/etc/nixos/`
|
||||
>
|
||||
> Then just add `./realip.nix` to your modules array.
|
||||
|
||||
```nix
|
||||
# New module in your modules array
|
||||
{
|
||||
|
|
|
|||
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