Created
August 23, 2019 17:52
-
-
Save rluisr/9a236b650083362925bcdf62c1bfbc97 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 | |
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