From c49baad276b20c8eb6e33b2551151408b52e2c24 Mon Sep 17 00:00:00 2001 From: Roxedus Date: Thu, 21 Jan 2021 16:52:23 +0100 Subject: [PATCH] SWAG-Real-IP: Fix bug if networking is not working It would produce a malformed line, stopping nginx from running if it failed to curl the list --- README.md | 8 +++++++- root/etc/cont-init.d/98-cloudflare-real-ip | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index baa64f8..1988bb5 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,10 @@ real_ip_recursive on; include /config/nginx/cf_real-ip.conf; ``` -I also recommend including your docker-network as a valid ip `set_real_ip_from 172.17.0.0/16;` in the snippet above. +~~I also recommend including your docker-network as a valid ip `set_real_ip_from 172.17.0.0/16;` in the snippet above.~~ + +This mod now also *tries* to set the real ip from the default route in the contaier. + +## Versions + +* **21.01.21:** - Fix bug when mod runs before internet-access. diff --git a/root/etc/cont-init.d/98-cloudflare-real-ip b/root/etc/cont-init.d/98-cloudflare-real-ip index 6f0ecba..541dbe1 100644 --- a/root/etc/cont-init.d/98-cloudflare-real-ip +++ b/root/etc/cont-init.d/98-cloudflare-real-ip @@ -4,7 +4,8 @@ printf "set_real_ip_from %b;\n" $({ curl -s "https://www.cloudflare.com/ips-v4" & - curl -s "https://www.cloudflare.com/ips-v6" -}) >/config/nginx/cf_real-ip.conf + curl -s "https://www.cloudflare.com/ips-v6" & + echo "$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p' | sed 's/\.[0-9]*$//')/16" +}) > /config/nginx/cf_real-ip.conf chown abc:abc /config/nginx/cf_real-ip.conf