diff --git a/docker-compose.yml b/docker-compose.yml index dc3f251a..2c3c430b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,15 +23,25 @@ services: build: context: ./services/nginx restart: always + networks: + - storedog-net ports: - "80:80" depends_on: - frontend - dd-agent + volumes: + - ./services/nginx/nginx.conf:/etc/nginx/nginx.conf + - ./services/nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./services/nginx/status.conf:/etc/nginx/conf.d/status.conf labels: - com.datadoghq.ad.logs: '[{"source": "nginx", "service": "nginx"}]' - networks: - - storedog-net + com.datadog.tags.env: '${DD_ENV}' + com.datadog.tags.service: 'store-nginx' + com.datadog.tags.version: '1.21.4' + com.datadoghq.ad.logs: '[{"source": "nginx", "service": "webserver"}]' + com.datadoghq.ad.check_names: '["nginx"]' + com.datadoghq.ad.init_configs: '[{}]' + com.datadoghq.ad.instances: '[{"nginx_status_url": "http://%%host%%:81/nginx_status/"}]' postgres: image: postgres:13-alpine restart: always diff --git a/services/nginx/Dockerfile b/services/nginx/Dockerfile index 30327866..33b30052 100644 --- a/services/nginx/Dockerfile +++ b/services/nginx/Dockerfile @@ -1,7 +1,42 @@ -FROM nginx:1.21.4 +ARG NGINX_VERSION=1.21.4 + +FROM nginx:$NGINX_VERSION + +ARG NGINX_VERSION=1.21.4 +ARG GEOIP2_VERSION=3.3 + +RUN mkdir -p /var/lib/GeoIP/ + +RUN apt-get update \ + && apt-get install -y \ + build-essential \ + libpcre++-dev \ + zlib1g-dev \ + libgeoip-dev \ + libmaxminddb-dev \ + wget \ + git + +RUN cd /opt \ + && git clone --depth 1 -b $GEOIP2_VERSION --single-branch https://github.com/leev/ngx_http_geoip2_module.git \ + && wget -O - http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz | tar zxfv - \ + && mv /opt/nginx-$NGINX_VERSION /opt/nginx \ + && cd /opt/nginx \ + && ./configure --with-compat --add-dynamic-module=/opt/ngx_http_geoip2_module \ + && make modules + +FROM nginx:$NGINX_VERSION + +COPY --from=0 /opt/nginx/objs/ngx_http_geoip2_module.so /usr/lib/nginx/modules +COPY nginx.conf /etc/nginx/nginx.conf COPY default.conf /etc/nginx/conf.d/default.conf COPY status.conf /etc/nginx/conf.d/status.conf +COPY GeoLite2-City.mmdb /var/lib/GeoIP/GeoLite2-City.mmdb +COPY GeoLite2-Country.mmdb /var/lib/GeoIP/GeoLite2-Country.mmdb + +RUN apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests libmaxminddb0 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && chmod -R 644 /usr/lib/nginx/modules/ngx_http_geoip2_module.so -LABEL "com.datadoghq.ad.check_names"='["nginx"]' -LABEL "com.datadoghq.ad.init_configs"='[{}]' -LABEL "com.datadoghq.ad.instances"='[{"nginx_status_url": "http://%%host%%:81/nginx_status/"}]' \ No newline at end of file diff --git a/services/nginx/GeoLite2-City.mmdb b/services/nginx/GeoLite2-City.mmdb new file mode 100644 index 00000000..badab331 Binary files /dev/null and b/services/nginx/GeoLite2-City.mmdb differ diff --git a/services/nginx/GeoLite2-Country.mmdb b/services/nginx/GeoLite2-Country.mmdb new file mode 100644 index 00000000..547b1096 Binary files /dev/null and b/services/nginx/GeoLite2-Country.mmdb differ diff --git a/services/nginx/nginx.conf b/services/nginx/nginx.conf new file mode 100644 index 00000000..1b8929c0 --- /dev/null +++ b/services/nginx/nginx.conf @@ -0,0 +1,37 @@ +load_module "modules/ngx_http_geoip2_module.so"; + +events { + worker_connections 1024; + # other event-related settings can go here +} + +http { + include /etc/nginx/conf.d/*.conf; + + geoip2 /var/lib/GeoIP/GeoLite2-Country.mmdb { + auto_reload 5m; + $geoip2_metadata_country_build metadata build_epoch; + $geoip2_data_country_code country iso_code; + $geoip2_data_country_name country names en; + } + + geoip2 /var/lib/GeoIP/GeoLite2-City.mmdb { + $geoip2_data_city_name default=Unknown city names en; + $geoip2_data_latitude default=0.0 location latitude; + $geoip2_data_longitude default=0.0 location longitude; + $geoip2_data_postal_code default=Unknown postal code; + } + + log_format main '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" ' + 'Country: $geoip2_data_country_name ($geoip2_data_country_code), ' + 'City: $geoip2_data_city_name, ' + 'Lat: $geoip2_data_latitude, ' + 'Long: $geoip2_data_longitude, ' + 'Postal Code: $geoip2_data_postal_code'; + + + access_log /var/log/nginx/access.log main; + +} diff --git a/services/nginx/status.conf b/services/nginx/status.conf index dd293457..9b50a8f9 100644 --- a/services/nginx/status.conf +++ b/services/nginx/status.conf @@ -3,7 +3,7 @@ server { server_name localhost; access_log off; - allow 172.43.0.0/16; + allow 0.0.0.0/0; deny all; location /nginx_status {