Skip to content

Instantly share code, notes, and snippets.

@Feiron
Created August 16, 2025 13:01
Show Gist options
  • Select an option

  • Save Feiron/cba02499ad2b90f658360c8cf6ea9e04 to your computer and use it in GitHub Desktop.

Select an option

Save Feiron/cba02499ad2b90f658360c8cf6ea9e04 to your computer and use it in GitHub Desktop.
[Проброс настоящего IP c cloudflare] #nginx #cloudflare
log_format real_ip '$http_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log real_ip;
# Доверенные прокси — IP-диапазоны Cloudflare
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
# Говорим nginx, что настоящий IP — в заголовке
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# Cloudflare также передаёт IP клиента в заголовке CF-Connecting-IP, который всегда содержит только один IP, и его проще использовать,
# чем X-Forwarded-For (в котором может быть цепочка).
real_ip_header CF-Connecting-IP;
real_ip_recursive on;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment