Created
December 24, 2016 12:52
-
-
Save AnttiKurittu/62643e6d7398ed3accfe4c4350c7ea78 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Get and refresh the Cloudflare IP range and set them in a configuration | |
# file for Nginx. Rememember to include this in your server directive | |
# with 'include /path/to/this/script.sh;' | |
# add this to your crontab with 'crontab -e' | |
# 30 5 * * * /etc/nginx/sites-available/get-cf-ip-range.sh | |
set -e | |
wget -q -P /etc/nginx/sites-available/ https://www.cloudflare.com/ips-v4 | |
wget -q -P /etc/nginx/sites-available/ https://www.cloudflare.com/ips-v6 | |
cat /etc/nginx/sites-available/ips-v6 >>/etc/nginx/sites-available/ips-v4 | |
echo "# Get cloudflare IP range and set real IP for logs." >/etc/nginx/sites-available/cloudflare-set-real-ip | |
for i in $(cat /etc/nginx/sites-available/ips-v4); | |
do echo "set_real_ip_from $i;" >>/etc/nginx/sites-available/cloudflare-set-real-ip; | |
done | |
echo "real_ip_header CF-Connecting-IP;" >>/etc/nginx/sites-available/cloudflare-set-real-ip | |
rm /etc/nginx/sites-available/ips-v* | |
/usr/sbin/nginx -t -q | |
/usr/sbin/nginx -s reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment