Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit c1c3cda

Browse files
committed
Merge pull request #1102 from aledbf/stats-by-country
[nginx-ingress-controller]: Add support for geoip in stats
2 parents e48decd + 084a54d commit c1c3cda

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ingress/controllers/nginx/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ RUN apt-get update && apt-get install -y \
1919
--no-install-recommends \
2020
&& rm -rf /var/lib/apt/lists/*
2121

22+
# Download of GeoIP databases
23+
RUN curl -sSL -o /etc/nginx/GeoIP.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz \
24+
&& curl -sSL -o /etc/nginx/GeoLiteCity.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz \
25+
&& gunzip /etc/nginx/GeoIP.dat.gz \
26+
&& gunzip /etc/nginx/GeoLiteCity.dat.gz
27+
2228
COPY nginx-ingress-controller /
2329
COPY nginx.tmpl /etc/nginx/template/nginx.tmpl
2430
COPY default.conf /etc/nginx/nginx.conf

ingress/controllers/nginx/nginx.tmpl

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ events {
1616
}
1717

1818
http {
19-
{{ if $cfg.enableVtsStatus}}vhost_traffic_status_zone shared:vhost_traffic_status:{{ $cfg.vtsStatusZoneSize }};{{ end }}
19+
{{/* databases used to determine the country depending on the client IP address */}}
20+
{{/* http://nginx.org/en/docs/http/ngx_http_geoip_module.html */}}
21+
{{/* this is require to calculate traffic for individual country using GeoIP in the status page */}}
22+
geoip_country /etc/nginx/GeoIP.dat;
23+
geoip_city /etc/nginx/GeoLiteCity.dat;
24+
25+
{{- if $cfg.enableVtsStatus }}
26+
vhost_traffic_status_zone shared:vhost_traffic_status:{{ $cfg.vtsStatusZoneSize }};
27+
vhost_traffic_status_filter_by_set_key $geoip_country_code country::*;
28+
{{ end -}}
2029

2130
# lus sectrion to return proper error codes when custom pages are used
2231
lua_package_path '.?.lua;./etc/nginx/lua/?.lua;/etc/nginx/lua/vendor/lua-resty-http/lib/?.lua;';
@@ -166,6 +175,8 @@ http {
166175
more_set_headers "Strict-Transport-Security: max-age={{ $cfg.hstsMaxAge }}{{ if $cfg.hstsIncludeSubdomains }}; includeSubDomains{{ end }}; preload";
167176
{{ end -}}
168177

178+
{{ if $cfg.enableVtsStatus }}vhost_traffic_status_filter_by_set_key $geoip_country_code country::$server_name;{{ end }}
179+
169180
{{ range $location := $server.Locations }}
170181
location {{ $location.Path }} {
171182
proxy_set_header Host $host;

0 commit comments

Comments
 (0)