M
M
mr_mescaline2016-12-25 10:36:17
bash
mr_mescaline, 2016-12-25 10:36:17

Have a look at the bash script.

you need to update (add) on the crown, the ip of the cloudflare proxy servers for nginx (set_real_ip_from).
although they are not often updated, but still I would not like to go to the server once again.
I found such a script in the open spaces (according to the author, it is fully working)

#!/bin/bash

# Location of the nginx config file that contains the CloudFlare IP addresses.
CF_NGINX_CONFIG="/etc/nginx/cloudflare"

# The URLs with the actual IP addresses used by CloudFlare.
CF_URL_IP4="https://www.cloudflare.com/ips-v4"
CF_URL_IP6="https://www.cloudflare.com/ips-v6"

# Temporary files.
CF_TEMP_IP4="/tmp/cloudflare-ips-v4.txt"
CF_TEMP_IP6="/tmp/cloudflare-ips-v6.txt"

# Download the files.
if [ -f /usr/bin/curl ];
then
    curl --silent --output $CF_TEMP_IP4 $CF_URL_IP4
    curl --silent --output $CF_TEMP_IP6 $CF_URL_IP6
elif [ -f /usr/bin/wget ];
then
    wget --quiet --output-document=$CF_TEMP_IP4 --no-check-certificate $CF_URL_IP4
    wget --quiet --output-document=$CF_TEMP_IP6 --no-check-certificate $CF_URL_IP6
else
    echo "Unable to download CloudFlare files."
    exit 1
fi

# Generate the new config file.
echo "# CloudFlare IP Ranges" > $CF_NGINX_CONFIG
echo "# Generated at $(date) by $0" >> $CF_NGINX_CONFIG
echo "" >> $CF_NGINX_CONFIG

echo "# - IPv4 ($CF_URL_IP4)" >> $CF_NGINX_CONFIG
awk '{ print "set_real_ip_from " $0 ";" }' $CF_TEMP_IP4 >> $CF_NGINX_CONFIG
echo "" >> $CF_NGINX_CONFIG

echo "# - IPv6 ($CF_URL_IP6)" >> $CF_NGINX_CONFIG
awk '{ print "set_real_ip_from " $0 ";" }' $CF_TEMP_IP6 >> $CF_NGINX_CONFIG
echo "" >> $CF_NGINX_CONFIG

echo "real_ip_header CF-Connecting-IP;" >> $CF_NGINX_CONFIG
echo "" >> $CF_NGINX_CONFIG

# Remove the temporary files.
rm $CF_TEMP_IP4 $CF_TEMP_IP6

# Reload the nginx config.
service nginx reload

--------------------
no config is created, it is not in temporary files either. the files themselves with ip lists are available ( https://www.cloudflare.com/ips-v4 and https://www.cloudflare.com/ips-v6)
if you type /home/scripts/cloudflare-update-ip- in the terminal ranges.sh > /dev/null 2>&1
outputs this:
/home/scripts/cloudflare-update-ip-ranges.sh
/home/scripts/cloudflare-update-ip-ranges.sh: line 29: /etc/nginx /cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 30: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 31: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 33: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 34: /etc/nginx /cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 35: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 37: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 38: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip -ranges.sh: line 39: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 41: /etc/nginx/cloudflare: Is
a directory
/home/scripts/cloudflare-update-ip-ranges.sh: line 42: /etc/nginx/cloudflare: Is
a directory
Reloading nginx: [ OK ]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Nikolaev, 2016-12-25
@nightvich

# Location of the nginx config file that contains the CloudFlare IP addresses.
CF_NGINX_CONFIG="/etc/nginx/cloudflare"
/home/scripts/cloudflare-update-ip-ranges.sh: line 29: /etc/nginx/cloudflare: Is
a directory

Try to write the correct path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question