diff --git a/controllers/nginx/Dockerfile b/controllers/nginx/Dockerfile index 08dbfb2f6..32e57ef13 100644 --- a/controllers/nginx/Dockerfile +++ b/controllers/nginx/Dockerfile @@ -19,6 +19,12 @@ RUN apt-get update && apt-get install -y \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/* +# Download of GeoIP databases +RUN curl -sSL -o /etc/nginx/GeoIP.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz \ + && curl -sSL -o /etc/nginx/GeoLiteCity.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz \ + && gunzip /etc/nginx/GeoIP.dat.gz \ + && gunzip /etc/nginx/GeoLiteCity.dat.gz + COPY nginx-ingress-controller / COPY nginx.tmpl /etc/nginx/template/nginx.tmpl COPY default.conf /etc/nginx/nginx.conf diff --git a/controllers/nginx/nginx.tmpl b/controllers/nginx/nginx.tmpl index 374240120..812f7f438 100644 --- a/controllers/nginx/nginx.tmpl +++ b/controllers/nginx/nginx.tmpl @@ -16,7 +16,16 @@ events { } http { - {{ if $cfg.enableVtsStatus}}vhost_traffic_status_zone shared:vhost_traffic_status:{{ $cfg.vtsStatusZoneSize }};{{ end }} + {{/* databases used to determine the country depending on the client IP address */}} + {{/* http://nginx.org/en/docs/http/ngx_http_geoip_module.html */}} + {{/* this is require to calculate traffic for individual country using GeoIP in the status page */}} + geoip_country /etc/nginx/GeoIP.dat; + geoip_city /etc/nginx/GeoLiteCity.dat; + + {{- if $cfg.enableVtsStatus }} + vhost_traffic_status_zone shared:vhost_traffic_status:{{ $cfg.vtsStatusZoneSize }}; + vhost_traffic_status_filter_by_set_key $geoip_country_code country::*; + {{ end -}} # lus sectrion to return proper error codes when custom pages are used lua_package_path '.?.lua;./etc/nginx/lua/?.lua;/etc/nginx/lua/vendor/lua-resty-http/lib/?.lua;'; @@ -166,6 +175,8 @@ http { more_set_headers "Strict-Transport-Security: max-age={{ $cfg.hstsMaxAge }}{{ if $cfg.hstsIncludeSubdomains }}; includeSubDomains{{ end }}; preload"; {{ end -}} + {{ if $cfg.enableVtsStatus }}vhost_traffic_status_filter_by_set_key $geoip_country_code country::$server_name;{{ end }} + {{ range $location := $server.Locations }} location {{ $location.Path }} { proxy_set_header Host $host;