Last active
March 25, 2025 04:55
-
-
Save devhammed/b55c3661310b9ee4e73b1e5e77bccd4c to your computer and use it in GitHub Desktop.
Script that automatically generates Cloudfare real-ips configuration for NGINX, you need to add `include /etc/nginx/cloudflare;` to the `http` block in `/etc/nginx/nginx.conf` file to activate.
This file contains hidden or 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 -eu | |
CLOUDFLARE_FILE_PATH=/etc/nginx/cloudflare | |
echo "# Cloudflare" > $CLOUDFLARE_FILE_PATH; | |
echo "" >> $CLOUDFLARE_FILE_PATH; | |
echo "# - IPv4" >> $CLOUDFLARE_FILE_PATH; | |
for i in `curl -s -L https://www.cloudflare.com/ips-v4`; do | |
echo "set_real_ip_from $i;" >> $CLOUDFLARE_FILE_PATH; | |
done | |
echo "" >> $CLOUDFLARE_FILE_PATH; | |
echo "# - IPv6" >> $CLOUDFLARE_FILE_PATH; | |
for i in `curl -s -L https://www.cloudflare.com/ips-v6`; do | |
echo "set_real_ip_from $i;" >> $CLOUDFLARE_FILE_PATH; | |
done | |
echo "" >> $CLOUDFLARE_FILE_PATH; | |
echo "real_ip_header CF-Connecting-IP;" >> $CLOUDFLARE_FILE_PATH; | |
nginx -t && systemctl reload nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment