Skip to content
Merged
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
16 changes: 13 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 39 additions & 4 deletions services/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/"}]'
Binary file added services/nginx/GeoLite2-City.mmdb
Binary file not shown.
Binary file added services/nginx/GeoLite2-Country.mmdb
Binary file not shown.
37 changes: 37 additions & 0 deletions services/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;

}
2 changes: 1 addition & 1 deletion services/nginx/status.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down