Skip to content

Commit b3cb2bc

Browse files
committed
Get Real Visitor IP Address (Restoring Visitor IPs) with Nginx and CloudFlare
Based on https://github.com/ergin/nginx-cloudflare-real-ip
1 parent fd30cfe commit b3cb2bc

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

docker/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ LABEL org.label-schema.schema-version="1.0" \
5858
org.label-schema.license="MIT" \
5959
org.label-schema.name="nginx-proxy-manager" \
6060
org.label-schema.description="Docker container for managing Nginx proxy hosts with a simple, powerful interface " \
61-
org.label-schema.url="https://github.com/jc21/nginx-proxy-manager" \
62-
org.label-schema.vcs-url="https://github.com/jc21/nginx-proxy-manager.git" \
63-
org.label-schema.cmd="docker run --rm -ti jc21/nginx-proxy-manager:latest"
61+
org.label-schema.url="https://github.com/Raffi/nginx-proxy-manager" \
62+
org.label-schema.vcs-url="https://github.com/Raffi/nginx-proxy-manager.git" \
63+
org.label-schema.cmd="docker run --rm -ti Raffi/nginx-proxy-manager:latest"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
CLOUDFLARE_FILE_PATH=${1:-/etc/nginx/cloudflare}
4+
5+
echo "#Cloudflare" > $CLOUDFLARE_FILE_PATH;
6+
echo "" >> $CLOUDFLARE_FILE_PATH;
7+
8+
echo "# - IPv4" >> $CLOUDFLARE_FILE_PATH;
9+
for i in `curl -s -L https://www.cloudflare.com/ips-v4`; do
10+
echo "set_real_ip_from $i;" >> $CLOUDFLARE_FILE_PATH;
11+
done
12+
13+
echo "" >> $CLOUDFLARE_FILE_PATH;
14+
echo "# - IPv6" >> $CLOUDFLARE_FILE_PATH;
15+
for i in `curl -s -L https://www.cloudflare.com/ips-v6`; do
16+
echo "set_real_ip_from $i;" >> $CLOUDFLARE_FILE_PATH;
17+
done
18+
19+
echo "" >> $CLOUDFLARE_FILE_PATH;
20+
echo "real_ip_header CF-Connecting-IP;" >> $CLOUDFLARE_FILE_PATH;
21+
22+
#test configuration and reload nginx
23+
nginx -t && systemctl reload nginx

docker/rootfs/etc/nginx/cloudflare

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Cloudflare
2+
3+
# - IPv4
4+
set_real_ip_from 173.245.48.0/20;
5+
set_real_ip_from 103.21.244.0/22;
6+
set_real_ip_from 103.22.200.0/22;
7+
set_real_ip_from 103.31.4.0/22;
8+
set_real_ip_from 141.101.64.0/18;
9+
set_real_ip_from 108.162.192.0/18;
10+
set_real_ip_from 190.93.240.0/20;
11+
set_real_ip_from 188.114.96.0/20;
12+
set_real_ip_from 197.234.240.0/22;
13+
set_real_ip_from 198.41.128.0/17;
14+
set_real_ip_from 162.158.0.0/15;
15+
set_real_ip_from 104.16.0.0/13;
16+
set_real_ip_from 104.24.0.0/14;
17+
set_real_ip_from 172.64.0.0/13;
18+
set_real_ip_from 131.0.72.0/22;
19+
20+
# - IPv6
21+
set_real_ip_from 2400:cb00::/32;
22+
set_real_ip_from 2606:4700::/32;
23+
set_real_ip_from 2803:f800::/32;
24+
set_real_ip_from 2405:b500::/32;
25+
set_real_ip_from 2405:8100::/32;
26+
set_real_ip_from 2a06:98c0::/29;
27+
set_real_ip_from 2c0f:f248::/32;
28+
29+
real_ip_header CF-Connecting-IP;

docker/rootfs/etc/nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ events {
1919
}
2020

2121
http {
22+
include /etc/nginx/cloudflare;
2223
include /etc/nginx/mime.types;
2324
default_type application/octet-stream;
2425
sendfile on;

0 commit comments

Comments
 (0)