[GH-ISSUE #12] Alternative approach using sed and some for loop variables #5

Open
opened 2026-02-25 22:30:23 +03:00 by kerem · 0 comments
Owner

Originally created by @jessuppi on GitHub (Aug 8, 2023).
Original GitHub issue: https://github.com/ergin/nginx-cloudflare-real-ip/issues/12

Hello @ergin and thank you very much for your work on this script, I came across it a few times and finally implemented your research into my SlickStack script after several users asked for it.

This is not so much a feature request, but in case you wanted to share an alternative way to build cloudflare.conf using sed and an existing boilerplate, it seems to work okay...

Ref: https://github.com/littlebizzy/slickstack/blob/master/bash/ss-install-nginx-cloudflare-ips.txt

## ipv4 list ##
CLOUDFLARE_IPV4_LIST=$(for i in `curl -s -L https://www.cloudflare.com/ips-v4`; do
    echo "set_real_ip_from $i;" >> /tmp/ips-v4.txt;
done)

sed -i -e '/@CLOUDFLARE_IPV4_LIST/{r /tmp/ips-v4.txt' -e 'd' -e '}' "${TMP_CLOUDFLARE_CONF}"

## ipv6 list ##
CLOUDFLARE_IPV6_LIST=$(for i in `curl -s -L https://www.cloudflare.com/ips-v6`; do
    echo "set_real_ip_from $i;" >> /tmp/ips-v6.txt;
done)

sed -i -e '/@CLOUDFLARE_IPV6_LIST/{r /tmp/ips-v6.txt' -e 'd' -e '}' "${TMP_CLOUDFLARE_CONF}"

This is an example boilerplate:

https://github.com/littlebizzy/slickstack/blob/master/modules/nginx/includes/cloudflare-conf.txt

And the placeholders in the boilerplate @CLOUDFLARE_IPV4_LIST and @CLOUDFLARE_IPV6_LIST get replaced via sed using your nifty bash for loop and a few tmp files.

Anyway I had never used sed this way before so just wanted to share. Thanks!

P.S. we credited you in the script comments at the bottom

Originally created by @jessuppi on GitHub (Aug 8, 2023). Original GitHub issue: https://github.com/ergin/nginx-cloudflare-real-ip/issues/12 Hello @ergin and thank you very much for your work on this script, I came across it a few times and finally implemented your research into my SlickStack script after several users asked for it. This is not so much a feature request, but in case you wanted to share an alternative way to build `cloudflare.conf` using `sed` and an existing boilerplate, it seems to work okay... Ref: https://github.com/littlebizzy/slickstack/blob/master/bash/ss-install-nginx-cloudflare-ips.txt ``` ## ipv4 list ## CLOUDFLARE_IPV4_LIST=$(for i in `curl -s -L https://www.cloudflare.com/ips-v4`; do echo "set_real_ip_from $i;" >> /tmp/ips-v4.txt; done) sed -i -e '/@CLOUDFLARE_IPV4_LIST/{r /tmp/ips-v4.txt' -e 'd' -e '}' "${TMP_CLOUDFLARE_CONF}" ## ipv6 list ## CLOUDFLARE_IPV6_LIST=$(for i in `curl -s -L https://www.cloudflare.com/ips-v6`; do echo "set_real_ip_from $i;" >> /tmp/ips-v6.txt; done) sed -i -e '/@CLOUDFLARE_IPV6_LIST/{r /tmp/ips-v6.txt' -e 'd' -e '}' "${TMP_CLOUDFLARE_CONF}" ``` This is an example boilerplate: https://github.com/littlebizzy/slickstack/blob/master/modules/nginx/includes/cloudflare-conf.txt And the placeholders in the boilerplate `@CLOUDFLARE_IPV4_LIST` and `@CLOUDFLARE_IPV6_LIST` get replaced via `sed` using your nifty bash for loop and a few tmp files. Anyway I had never used `sed` this way before so just wanted to share. Thanks! P.S. we credited you in the script comments at the bottom
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-cloudflare-real-ip#5
No description provided.