Last active
July 31, 2016 15:54
-
-
Save ryush00/e2c5065ec0072f8022534ff54bda804d to your computer and use it in GitHub Desktop.
Add ip subnets to nginx config from cloudflare website.
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 | |
# The original source | |
# I don't know who made it. | |
# Update cloudflare.conf with new IPs | |
# | |
cloudFlareConf="/etc/nginx/conf.d/cloudflare.conf" | |
IPV4=$(curl -s "https://www.cloudflare.com/ips-v4") | |
IPV6=$(curl -s "https://www.cloudflare.com/ips-v6") | |
DATE="$(date)" | |
echo "# Last updated ${DATE}" > ${cloudFlareConf} | |
for IPV4ip in ${IPV4} | |
do | |
echo "set_real_ip_from ${IPV4ip};" >> ${cloudFlareConf} | |
done | |
for IPV6ip in ${IPV6} | |
do | |
echo "set_real_ip_from ${IPV6ip};" >> ${cloudFlareConf} | |
done | |
echo "real_ip_header CF-Connecting-IP;" >> ${cloudFlareConf} |
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 | |
# Made by ryush00 | |
# Update cloudflare.conf with new IPs | |
# It works with Google Cloud Network Load Balancer | |
# Subnet mask may not exact. | |
cloudFlareConf="/etc/nginx/conf.d/cloudflare.conf" | |
IPV4=$(curl -s "https://www.cloudflare.com/ips-v4") | |
IPV6=$(curl -s "https://www.cloudflare.com/ips-v6") | |
DATE="$(date)" | |
echo "# Last updated ${DATE}" > ${cloudFlareConf} | |
for IPV4ip in ${IPV4} | |
do | |
echo "set_real_ip_from ${IPV4ip};" >> ${cloudFlareConf} | |
done | |
for IPV6ip in ${IPV6} | |
do | |
echo "set_real_ip_from ${IPV6ip};" >> ${cloudFlareConf} | |
done | |
echo "set_real_ip_from 130.211.0.0/16;" >> ${cloudFlareConf} | |
echo "real_ip_header X-Forwarded-For;" >> ${cloudFlareConf} | |
echo "real_ip_recursive on;" >> ${cloudFlareConf} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment