Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions nginx/templates/01_geoip2.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ---------------------------------------------------------
# GeoIP2
# ---------------------------------------------------------

# База MaxMind GeoLite2 Country
# файл должен быть заранее скачан и примонтирован
geoip2 /etc/angie/geoip/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_country_code source=$geoip_source_ip country iso_code;
$geoip2_country_name source=$http_x_forwarded_for country names ru;
}


# если есть X-Debug-IP — используем его, иначе реальный адрес
map $http_x_debug_ip $geoip_source_ip {
default $remote_addr;
~^\d+\.\d+\.\d+\.\d+$ $http_x_debug_ip;
}


# ---------------------------------------------------------
# Country map
# ---------------------------------------------------------
map $geoip2_country_code $is_ru {
default 0;
RU 1;
}

log_format geoip_debug
'real_ip=$remote_addr '
'geoip_ip=$geoip_source_ip '
'country=$geoip2_country_code '
'is_ru=$is_ru '
'status=$status';

# ---------------------------------------------------------
# Geo-based origin selection
# ---------------------------------------------------------
map $is_ru $target_origin {
1 ru.${ ORIGIN_NAME };
default ${ ORIGIN_NAME };
}
10 changes: 9 additions & 1 deletion nginx/templates/edge-https-proxy.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ server {
# ---------------------------------------------------------
server {
listen 443 ssl;
server_name *.${ORIGIN_NAME};
server_name *.${ ORIGIN_NAME };

# SSL сертификаты (скопированы с origin / CF origin cert)
ssl_certificate /etc/nginx/certs/fullchain.pem;
Expand All @@ -40,6 +40,14 @@ server {
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1h;

# -----------------------------------------------------
# Geo redirect for non-RU traffic
# -----------------------------------------------------
# if используется ТОЛЬКО для return — это безопасно
if ($is_ru = 0) {
return 302 https://${ ORIGIN_NAME }$request_uri;
}

# -----------------------------------------------------
# Proxy
# -----------------------------------------------------
Expand Down