From 1d30908eb46c68fb59fc5cb9386cd93c1fb1e8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Fernandes?= Date: Sun, 24 Nov 2024 15:12:56 +0000 Subject: [PATCH] changed default log to json, added cmd --- .gitea/workflows/docker-image.deploy.yml | 2 + docker/nginx-geoip.Dockerfile | 9 ++++- docker/nginx-geoip.conf | 47 +++++++++++++++++++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/docker-image.deploy.yml b/.gitea/workflows/docker-image.deploy.yml index 04e8430..bcc6013 100644 --- a/.gitea/workflows/docker-image.deploy.yml +++ b/.gitea/workflows/docker-image.deploy.yml @@ -3,6 +3,8 @@ on: paths: - "docker/**" - ".gitea/**" + schedule: + - cron: "0 02 * * *" jobs: build-docker-image: diff --git a/docker/nginx-geoip.Dockerfile b/docker/nginx-geoip.Dockerfile index deec805..b2a4cca 100644 --- a/docker/nginx-geoip.Dockerfile +++ b/docker/nginx-geoip.Dockerfile @@ -1,6 +1,9 @@ #tag nginx-geoip FROM nginx + +#RUN apt update -y && apt install -y logrotate && apt install -y cron + COPY nginx-geoip.conf /etc/nginx/nginx.conf @@ -16,4 +19,8 @@ RUN gzip -d city.dat.gz RUN cp city.dat /etc/nginx/dbip-city.dat RUN mkdir /etc/nginx/conf.d/streams -RUN mkdir /etc/nginx/conf.d/sites \ No newline at end of file +RUN mkdir /etc/nginx/conf.d/sites + + +#CMD service cron start && while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off"; +CMD service while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off"; \ No newline at end of file diff --git a/docker/nginx-geoip.conf b/docker/nginx-geoip.conf index 4c20125..e9b99da 100644 --- a/docker/nginx-geoip.conf +++ b/docker/nginx-geoip.conf @@ -15,7 +15,52 @@ http { '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$geoip_country_code"'; - access_log /var/log/nginx/access.log main; + + log_format json_log_format escape=json '{' + '"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution + '"connection": "$connection", ' # connection serial number + '"connection_requests": "$connection_requests", ' # number of requests made in connection + '"pid": "$pid", ' # process pid + '"request_id": "$request_id", ' # the unique request id + '"request_length": "$request_length", ' # request length (including headers and body) + '"remote_addr": "$remote_addr", ' # client IP + '"remote_user": "$remote_user", ' # client HTTP username + '"remote_port": "$remote_port", ' # client port + '"time_local": "$time_local", ' + '"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format + '"request": "$request", ' # full path no arguments if the request + '"request_uri": "$request_uri", ' # full path and arguments if the request + '"args": "$args", ' # args + '"status": "$status", ' # response status code + '"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client + '"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client + '"http_referer": "$http_referer", ' # HTTP referer + '"http_user_agent": "$http_user_agent", ' # user agent + '"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for + '"http_host": "$http_host", ' # the request Host: header + '"server_name": "$server_name", ' # the name of the vhost serving the request + '"request_time": "$request_time", ' # request processing time in seconds with msec resolution + '"upstream": "$upstream_addr", ' # upstream backend server for proxied requests + '"upstream_connect_time": "$upstream_connect_time", ' # upstream handshake time incl. TLS + '"upstream_header_time": "$upstream_header_time", ' # time spent receiving upstream headers + '"upstream_response_time": "$upstream_response_time", ' # time spend receiving upstream body + '"upstream_response_length": "$upstream_response_length", ' # upstream response length + '"upstream_cache_status": "$upstream_cache_status", ' # cache HIT/MISS where applicable + '"ssl_protocol": "$ssl_protocol", ' # TLS protocol + '"ssl_cipher": "$ssl_cipher", ' # TLS cipher + '"scheme": "$scheme", ' # http or https + '"request_method": "$request_method", ' # request method + '"server_protocol": "$server_protocol", ' # request protocol, like HTTP/1.1 or HTTP/2.0 + '"pipe": "$pipe", ' # "p" if request was pipelined, "." otherwise + '"gzip_ratio": "$gzip_ratio", ' + '"http_cf_ray": "$http_cf_ray", ' + '"geoip_country_code": "$geoip_country_code", ' + '"geoip_country_name": "$geoip_country_name", ' + '"geoip_city": "$geoip_city"' + '}'; + + #access_log /var/log/nginx/access.log main; + access_log /var/log/nginx/access.log json_log_format; sendfile on; #tcp_nopush on;