Skip to content

Instantly share code, notes, and snippets.

@rluisr
Created August 23, 2019 17:52
Show Gist options
  • Save rluisr/9a236b650083362925bcdf62c1bfbc97 to your computer and use it in GitHub Desktop.
Save rluisr/9a236b650083362925bcdf62c1bfbc97 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
cf_ips() {
echo "# https://www.cloudflare.com/ips"
echo 'geo $realip_remote_addr $cf {'
echo -e "\tdefault 0;"
for type in v4 v6; do
echo -e "\t# IP$type"
curl -s "https://www.cloudflare.com/ips-$type" | sed "s|^|\t|g" | sed "s|\$| 1;|g"
done
echo "}"
}
cf_ips > /etc/nginx/conf_extra.d/allow-cloudflare-only.conf
nginx -t && systemctl restart nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment