<commit_before># Hydrate nginx real\_ip values

## What is this?

I'm prepping a new webhost to be served behind CloudFlare. CloudFlare advises that you will need to implement the `real_ip` module if you use nginx and want to know where your traffic is really coming from. The method to do so is described here:

https://support.cloudflare.com/hc/en-us/articles/200170706-How-do-I-restore-original-visitor-IP-with-Nginx-

Below the list of CloudFlare IP addresses is the following caveat:

> NB: That list of prefixes needs to be updated regularly

It's unclear what the frequency of "regularly" is, but clearly we need to monitor this list for updates. If we need to monitor this list for updates, then we may as well assign that task to a robot. If the robot is monitoring the list, then it may as well be responsible for updating the nginx configuration too. Here's a script to do just that.

## How it works

Hopefully the script is easy to parse, but just in case it isn't, here is what it does:

1. Downloads a list of return-delimited IPv4 and IPv6 addresses from CloudFlare
1. Cleans `/etc/nginx/real_ip.conf`
1. Validates each IP address and writes valid ones into `/etc/nginx/real_ip.conf`
1. Reloads nginx via `/bin/systemctl`

## How to use it

Every setup is a little different, so this will not necessarily be a "drop-in" addition. It's simple and short enough to modify to your needs. As a set of general guidelines though:

1. Install the script somewhere convenient like `/usr/local/bin/`
1. Run the script and validate that `/etc/nginx/real_ip.conf` looks sane
1. Setup a cron to run the script daily
1. Add `include /etc/nginx/real_ip.conf` to your nginx config(s)



## Danger

This script makes certain assumptions which may cause you grief:

- The script cleans `/etc/nginx/real_ip.conf` before validating IP addresses
  - Ideally the script should abort if no IPv4 or IPv6 addresses are found
- The script assumes a return-delimited list
- The script assumes you are using CloudFlare<commit_msg>Lowercase "flare" in "Cloudflare" for README<commit_after># Hydrate nginx real\_ip values

## What is this?

I'm prepping a new webhost to be served behind Cloudflare. Cloudflare advises that you will need to implement the `real_ip` module if you use nginx and want to know where your traffic is really coming from. The method to do so is described here:

https://support.cloudflare.com/hc/en-us/articles/200170706-How-do-I-restore-original-visitor-IP-with-Nginx-

Below the list of Cloudflare IP addresses is the following caveat:

> NB: That list of prefixes needs to be updated regularly

It's unclear what the frequency of "regularly" is, but clearly we need to monitor this list for updates. If we need to monitor this list for updates, then we may as well assign that task to a robot. If the robot is monitoring the list, then it may as well be responsible for updating the nginx configuration too. Here's a script to do just that.

## How it works

Hopefully the script is easy to parse, but just in case it isn't, here is what it does:

1. Downloads a list of return-delimited IPv4 and IPv6 addresses from Cloudflare
1. Cleans `/etc/nginx/real_ip.conf`
1. Validates each IP address and writes valid ones into `/etc/nginx/real_ip.conf`
1. Reloads nginx via `/bin/systemctl`

## How to use it

Every setup is a little different, so this will not necessarily be a "drop-in" addition. It's simple and short enough to modify to your needs. As a set of general guidelines though:

1. Install the script somewhere convenient like `/usr/local/bin/`
1. Run the script and validate that `/etc/nginx/real_ip.conf` looks sane
1. Setup a cron to run the script daily
1. Add `include /etc/nginx/real_ip.conf` to your nginx config(s)



## Danger

This script makes certain assumptions which may cause you grief:

- The script cleans `/etc/nginx/real_ip.conf` before validating IP addresses
  - Ideally the script should abort if no IPv4 or IPv6 addresses are found
- The script assumes a return-delimited list
- The script assumes you are using Cloudflare
{'fraction_non_alphanumeric': 0.06147037128104254, 'fraction_numerical': 0.010327022375215147, 'mean_word_length': 4.009852216748769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '277787', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1141, 'n_words': 618}