Created
February 20, 2020 14:06
-
-
Save nczz/8b7205a43c92f6fb8256ded5e3cecbee to your computer and use it in GitHub Desktop.
Nginx 取回 Cloudflare 代理後的瀏覽者真實 IP(搭配 http_realip_module 模組) Ref: https://virtubox.github.io/nginx-cloudflare-real-ip/
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 | |
if [ -z "$(command -v curl)" ]; then | |
echo "####################################" | |
echo "Installing CURL" | |
echo "####################################" | |
apt-get update | |
apt-get install curl -y | |
fi | |
CURL_BIN=$(command -v curl) | |
CF_IPV4=$($CURL_BIN -sL https://www.cloudflare.com/ips-v4) | |
CF_IPV6=$($CURL_BIN -sL https://www.cloudflare.com/ips-v6) | |
echo '' > cloudflare.conf | |
echo "####################################" | |
echo "Adding Cloudflare IPv4" | |
echo "####################################" | |
for cf_ip4 in $CF_IPV4; do | |
echo "set_real_ip_from $cf_ip4;" >> cloudflare.conf | |
done | |
echo "####################################" | |
echo "Adding Cloudflare IPv6" | |
echo "####################################" | |
for cf_ip6 in $CF_IPV6; do | |
echo "set_real_ip_from $cf_ip6;" >> cloudflare.conf | |
done | |
echo 'real_ip_header CF-Connecting-IP;' >> cloudflare.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment