Skip to content

Instantly share code, notes, and snippets.

@ryush00
Last active July 31, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryush00/e2c5065ec0072f8022534ff54bda804d to your computer and use it in GitHub Desktop.
Save ryush00/e2c5065ec0072f8022534ff54bda804d to your computer and use it in GitHub Desktop.
Add ip subnets to nginx config from cloudflare website.
#! /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}
#! /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