diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c642da7..79b85f9 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,8 +5,9 @@ set -e # Ensure nginx can write to the shared logs directory mkdir -p /logs && chown nginx:nginx /logs -# Render nginx config from template -sed "s|__API_UPSTREAM__|${API_UPSTREAM}|g" /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf +# Render nginx config from template to /etc/nginx/nginx.conf +# (full config, not conf.d/ snippet — avoids Alpine include nesting issues) +sed "s|__API_UPSTREAM__|${API_UPSTREAM}|g" /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/nginx.conf # Render client-side config.json for fallback use envsubst '${API_PUBLIC_URL}' < /usr/share/nginx/html/config.json.template > /usr/share/nginx/html/config.json diff --git a/nginx.conf.template b/nginx.conf.template index c5eac8a..0d61aba 100644 --- a/nginx.conf.template +++ b/nginx.conf.template @@ -1,23 +1,34 @@ -# Map ISO timestamp to date-only string for daily log rotation -map $time_iso8601 $log_date { - "~^(?\d{4}-\d{2}-\d{2})" $date; - default "unknown"; +# Full nginx configuration — rendered to /etc/nginx/nginx.conf +# (NOT placed in conf.d/ to avoid include nesting issues with Alpine nginx) + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; } -log_format kmtn_json escape=json - '{' - '"time":"$time_iso8601",' - '"remote_addr":"$remote_addr",' - '"x_forwarded_for":"$http_x_forwarded_for"' - '}'; +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; -access_log /logs/access-$log_date.log kmtn_json; + log_format kmtn_json escape=json + '{' + '"time":"$time_iso8601",' + '"remote_addr":"$remote_addr",' + '"x_forwarded_for":"$http_x_forwarded_for"' + '}'; -upstream ssr_backend { - server 127.0.0.1:4200; -} + access_log /logs/access.log kmtn_json; + sendfile on; -server { + upstream ssr_backend { + server 127.0.0.1:4200; + } + + server { listen 80; server_name _; root /usr/share/nginx/html; @@ -83,3 +94,4 @@ server { add_header X-Powered-By "Angular SSR" always; } } +}