From e26a89ee5a48bd88d83b591e85ffab22644623b2 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 15:15:41 +0100 Subject: [PATCH 01/12] feat(jeuIA): store nginx logs --- nginx/nginx.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 4070a4c7e..44dc4baa6 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -15,7 +15,10 @@ http { '"$http_user_agent" "$http_x_forwarded_for"' '"$upstream_uri"'; + # Default log to stdout access_log /var/log/nginx/access.log main; + # Also write to file to persist logs + access_log /var/log/nginx/persist/access.$time_local.log main; sendfile on; -- GitLab From f2e8b790ce62023cda191b0beeb0752df3f16d26 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 15:39:44 +0100 Subject: [PATCH 02/12] get nginx.conf default from official nginx-unprivileged:1.25 image --- Dockerfile | 2 ++ nginx/nginx.conf | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index c6467e5de..606e4e72a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,8 @@ RUN npm run build:prod # Stage 1, based on Nginx, to have only the compiled app FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 +COPY nginx/nginx.conf /etc/nginx/nginx.conf + # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 44dc4baa6..2068ff231 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,12 +1,21 @@ -worker_processes 1; -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /tmp/nginx.pid; + events { worker_connections 1024; } + http { + proxy_temp_path /tmp/proxy_temp; + client_body_temp_path /tmp/client_temp; + fastcgi_temp_path /tmp/fastcgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + scgi_temp_path /tmp/scgi_temp; + include /etc/nginx/mime.types; default_type application/octet-stream; @@ -15,20 +24,20 @@ http { '"$http_user_agent" "$http_x_forwarded_for"' '"$upstream_uri"'; - # Default log to stdout + # Default log which is redirected to stdout access_log /var/log/nginx/access.log main; # Also write to file to persist logs access_log /var/log/nginx/persist/access.$time_local.log main; sendfile on; + #tcp_nopush on; keepalive_timeout 65; - gzip on; + #gzip on; include /etc/nginx/conf.d/*.conf; # Max Body Size client_max_body_size 10M; - -} +} \ No newline at end of file -- GitLab From 06d556ffa5eb72a5b111a1aec04d923e4f090854 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 15:52:18 +0100 Subject: [PATCH 03/12] fix --- nginx/nginx.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 2068ff231..1b97c5442 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -21,8 +21,7 @@ http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"' - '"$upstream_uri"'; + '"$http_user_agent" "$http_x_forwarded_for"'; # Default log which is redirected to stdout access_log /var/log/nginx/access.log main; -- GitLab From a82c4b066a9e62215dc7a43447f43d3c1009ef45 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 16:03:40 +0100 Subject: [PATCH 04/12] fix --- Dockerfile | 2 ++ nginx/nginx.conf | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 606e4e72a..c70010694 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,9 @@ RUN npm run build:prod # Stage 1, based on Nginx, to have only the compiled app FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 +# Copy custom conf to write logs into file to persist them COPY nginx/nginx.conf /etc/nginx/nginx.conf +RUN mkdir -p /var/log/nginx/persist # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 1b97c5442..7c6dadaf7 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -26,7 +26,7 @@ http { # Default log which is redirected to stdout access_log /var/log/nginx/access.log main; # Also write to file to persist logs - access_log /var/log/nginx/persist/access.$time_local.log main; + access_log /var/log/nginx/persist/access.$year-$month-$day.log main; sendfile on; #tcp_nopush on; -- GitLab From 745de3b9f99376442345a2e7d30fb6310e5d4ce1 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 16:13:21 +0100 Subject: [PATCH 05/12] fix permission denied path --- Dockerfile | 2 +- nginx/nginx.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c70010694..cac50e47c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 # Copy custom conf to write logs into file to persist them COPY nginx/nginx.conf /etc/nginx/nginx.conf -RUN mkdir -p /var/log/nginx/persist +RUN mkdir -p /tmp/log # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 7c6dadaf7..99c4899b1 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -26,7 +26,7 @@ http { # Default log which is redirected to stdout access_log /var/log/nginx/access.log main; # Also write to file to persist logs - access_log /var/log/nginx/persist/access.$year-$month-$day.log main; + access_log /tmp/log/access.$year-$month-$day.log main; sendfile on; #tcp_nopush on; -- GitLab From 6b977ef23e11e6581cd17bc7ccb02c7fb1eb6453 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 16:41:14 +0100 Subject: [PATCH 06/12] fix --- nginx/nginx.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 99c4899b1..9b85d572a 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -8,6 +8,18 @@ events { worker_connections 1024; } +map $time_iso8601 $year { + default '0000'; + "~^(\d{4})-(\d{2})-(\d{2})" $1; +} +map $time_iso8601 $month { + default '00'; + "~^(\d{4})-(\d{2})-(\d{2})" $2; +} +map $time_iso8601 $day { + default '00'; + "~^(\d{4})-(\d{2})-(\d{2})" $3; +} http { proxy_temp_path /tmp/proxy_temp; -- GitLab From ced59e53be8052da6a58f8bd2fb853d99464fe4c Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 16:50:01 +0100 Subject: [PATCH 07/12] test --- nginx/nginx.conf | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 9b85d572a..229a30885 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -8,18 +8,6 @@ events { worker_connections 1024; } -map $time_iso8601 $year { - default '0000'; - "~^(\d{4})-(\d{2})-(\d{2})" $1; -} -map $time_iso8601 $month { - default '00'; - "~^(\d{4})-(\d{2})-(\d{2})" $2; -} -map $time_iso8601 $day { - default '00'; - "~^(\d{4})-(\d{2})-(\d{2})" $3; -} http { proxy_temp_path /tmp/proxy_temp; @@ -35,6 +23,19 @@ http { '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; + map $time_iso8601 $year { + default '0000'; + "~^(\d{4})-(\d{2})-(\d{2})" $1; + } + map $time_iso8601 $month { + default '00'; + "~^(\d{4})-(\d{2})-(\d{2})" $2; + } + map $time_iso8601 $day { + default '00'; + "~^(\d{4})-(\d{2})-(\d{2})" $3; + } + # Default log which is redirected to stdout access_log /var/log/nginx/access.log main; # Also write to file to persist logs -- GitLab From 347caf8fb7ffb5845206448b0104ae3b912c79c6 Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 17:12:08 +0100 Subject: [PATCH 08/12] fix rights --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cac50e47c..42198e25d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 # Copy custom conf to write logs into file to persist them COPY nginx/nginx.conf /etc/nginx/nginx.conf -RUN mkdir -p /tmp/log +RUN mkdir -p /tmp/log && chgrp 0 /tmp/log && chmod g+w /tmp/log # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template -- GitLab From afb54a5b3c033d755d94fe2c8249a59c9eaba45b Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 17:16:35 +0100 Subject: [PATCH 09/12] test --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 42198e25d..b3358c7fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 # Copy custom conf to write logs into file to persist them COPY nginx/nginx.conf /etc/nginx/nginx.conf -RUN mkdir -p /tmp/log && chgrp 0 /tmp/log && chmod g+w /tmp/log +RUN mkdir -p /tmp/log && chmod g+w /tmp/log # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template -- GitLab From 6cefdc8dfc5dfbad56c2c4e493343e40bcd475fb Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Thu, 20 Mar 2025 17:22:08 +0100 Subject: [PATCH 10/12] fix --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b3358c7fa..00a084e7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 # Copy custom conf to write logs into file to persist them COPY nginx/nginx.conf /etc/nginx/nginx.conf -RUN mkdir -p /tmp/log && chmod g+w /tmp/log +RUN mkdir -p /tmp/log && chmod a+w /tmp/log # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template -- GitLab From 702936a0569257c2e5368f9aef5344524d6c1bdd Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Fri, 21 Mar 2025 10:17:45 +0100 Subject: [PATCH 11/12] location /shared/jeuAieAieIA --- Dockerfile | 5 --- nginx/nginx.conf | 55 --------------------------- nginx/templates/default.conf.template | 18 +++++++++ 3 files changed, 18 insertions(+), 60 deletions(-) delete mode 100644 nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile index 00a084e7a..daf06e71e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,6 @@ COPY angular.json . COPY tsconfig.json . COPY tsconfig.app.json . COPY ngsw-config.json . -COPY /nginx/nginx.conf . COPY /src ./src ARG conf @@ -27,10 +26,6 @@ RUN npm run build:prod # Stage 1, based on Nginx, to have only the compiled app FROM ${DEPENDENCY_PROXY}nginxinc/nginx-unprivileged:1.25 -# Copy custom conf to write logs into file to persist them -COPY nginx/nginx.conf /etc/nginx/nginx.conf -RUN mkdir -p /tmp/log && chmod a+w /tmp/log - # Copy nginx modified conf with template (cf. "Using environment variables in nginx configuration" in https://hub.docker.com/_/nginx ) COPY nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template diff --git a/nginx/nginx.conf b/nginx/nginx.conf deleted file mode 100644 index 229a30885..000000000 --- a/nginx/nginx.conf +++ /dev/null @@ -1,55 +0,0 @@ -worker_processes auto; - -error_log /var/log/nginx/error.log notice; -pid /tmp/nginx.pid; - - -events { - worker_connections 1024; -} - - -http { - proxy_temp_path /tmp/proxy_temp; - client_body_temp_path /tmp/client_temp; - fastcgi_temp_path /tmp/fastcgi_temp; - uwsgi_temp_path /tmp/uwsgi_temp; - scgi_temp_path /tmp/scgi_temp; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - map $time_iso8601 $year { - default '0000'; - "~^(\d{4})-(\d{2})-(\d{2})" $1; - } - map $time_iso8601 $month { - default '00'; - "~^(\d{4})-(\d{2})-(\d{2})" $2; - } - map $time_iso8601 $day { - default '00'; - "~^(\d{4})-(\d{2})-(\d{2})" $3; - } - - # Default log which is redirected to stdout - access_log /var/log/nginx/access.log main; - # Also write to file to persist logs - access_log /tmp/log/access.$year-$month-$day.log main; - - sendfile on; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; - - # Max Body Size - client_max_body_size 10M; -} \ No newline at end of file diff --git a/nginx/templates/default.conf.template b/nginx/templates/default.conf.template index cec97a3a3..39ebd03b1 100644 --- a/nginx/templates/default.conf.template +++ b/nginx/templates/default.conf.template @@ -23,6 +23,19 @@ map $http_user_agent $prerender { "~*discordbot" 1; } +map $time_iso8601 $year { + default '0000'; + "~^(\d{4})-(\d{2})-(\d{2})" $1; +} +map $time_iso8601 $month { + default '00'; + "~^(\d{4})-(\d{2})-(\d{2})" $2; +} +map $time_iso8601 $day { + default '00'; + "~^(\d{4})-(\d{2})-(\d{2})" $3; +} + server { listen 8080 default_server; @@ -42,6 +55,11 @@ server { proxy_pass https://data.grandlyon.com/fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json; } + # Persist logs to a daily file + location /shared/jeuAieAieIA { + access_log /usr/share/nginx/html/shared/jeuAieAieIA/stats/log/access.$year-$month-$day.log main; + } + location / { add_header X-Frame-Options SAMEORIGIN always; add_header X-Content-Type-Options nosniff; -- GitLab From 0824c8d198cbba4315372b7535c37ad89f41557d Mon Sep 17 00:00:00 2001 From: Etienne Loupias <eloupias@grandlyon.com> Date: Fri, 21 Mar 2025 10:34:44 +0100 Subject: [PATCH 12/12] fix stdout --- nginx/templates/default.conf.template | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nginx/templates/default.conf.template b/nginx/templates/default.conf.template index 39ebd03b1..dc599d607 100644 --- a/nginx/templates/default.conf.template +++ b/nginx/templates/default.conf.template @@ -55,9 +55,12 @@ server { proxy_pass https://data.grandlyon.com/fr/datapusher/ws/grandlyon/adr_voie_lieu.adrcomgl/all.json; } - # Persist logs to a daily file + # Persist logs for jeuAieAieIA location /shared/jeuAieAieIA { - access_log /usr/share/nginx/html/shared/jeuAieAieIA/stats/log/access.$year-$month-$day.log main; + # Default log which is redirected to stdout (must be reset in this block because of "access_log" below) + access_log /var/log/nginx/access.log main; + # And also write to a daily file + access_log /usr/share/nginx/html/shared/jeuAieAieIA/stats/log/access.$year-$month-$day.log main; } location / { -- GitLab