|
| 1 | +apiVersion: v1 |
| 2 | +kind: ConfigMap |
| 3 | +metadata: |
| 4 | + name: {{ include "conversion-guide.fullname" . }}-nginx |
| 5 | + labels: |
| 6 | + {{- include "conversion-guide.labels" . | nindent 4 }} |
| 7 | +data: |
| 8 | + default.conf: | |
| 9 | + # ---------------------------------------- |
| 10 | + # HTTP-level logging & helpers |
| 11 | + # ---------------------------------------- |
| 12 | +
|
| 13 | + # Flag kubelet health probes by User-Agent |
| 14 | + map $http_user_agent $is_probe { default 0; ~kube-probe 1; } |
| 15 | +
|
| 16 | + # Flag error statuses |
| 17 | + map $status $is_error { default 0; ~^[45] 1; } |
| 18 | +
|
| 19 | + # Only log failing probe requests |
| 20 | + map "$is_probe:$is_error" $log_probe_fail { default 0; "1:1" 1; } |
| 21 | +
|
| 22 | + # Log all non-probe requests (browsers/APIs) |
| 23 | + map $is_probe $not_probe { 0 1; 1 0; } |
| 24 | +
|
| 25 | + # JSON access log for normal traffic |
| 26 | + log_format json escape=json |
| 27 | + '{' |
| 28 | + '"ts":"$time_iso8601",' |
| 29 | + '"remote":"$remote_addr",' |
| 30 | + '"method":"$request_method",' |
| 31 | + '"uri":"$request_uri",' |
| 32 | + '"status":$status,' |
| 33 | + '"bytes":$body_bytes_sent,' |
| 34 | + '"rt":$request_time,' |
| 35 | + '"ref":"$http_referer",' |
| 36 | + '"ua":"$http_user_agent",' |
| 37 | + '"req_id":"$request_id"' |
| 38 | + '}'; |
| 39 | +
|
| 40 | + # Compact format for probe logs |
| 41 | + log_format probe '$remote_addr - $time_local "$request" $status rt=$request_time'; |
| 42 | +
|
| 43 | + # Send error logs to stderr |
| 44 | + error_log /dev/stderr warn; |
| 45 | +
|
| 46 | +
|
| 47 | + # ---------------------------------------- |
| 48 | + # Main server |
| 49 | + # ---------------------------------------- |
| 50 | + server { |
| 51 | + listen 8080; |
| 52 | + server_name _; |
| 53 | +
|
| 54 | + root /usr/share/nginx/html; |
| 55 | + index index.html; |
| 56 | +
|
| 57 | + absolute_redirect off; |
| 58 | + port_in_redirect off; |
| 59 | + server_name_in_redirect off; |
| 60 | +
|
| 61 | + # Access logging: |
| 62 | + access_log /dev/stdout json if=$not_probe; # all non-probe requests |
| 63 | + access_log /dev/stdout probe if=$log_probe_fail; # ONLY failing probes |
| 64 | +
|
| 65 | + # Include MIME types |
| 66 | + include /etc/nginx/mime.types; |
| 67 | +
|
| 68 | + # On-the-fly compression for text-heavy responses |
| 69 | + gzip on; |
| 70 | + gzip_types text/plain text/css text/javascript application/javascript application/json image/svg+xml; |
| 71 | + gzip_min_length 256; |
| 72 | + gzip_vary on; |
| 73 | +
|
| 74 | + # Serve pre-compressed .gz files when available (forward-looking) |
| 75 | + gzip_static on; |
| 76 | +
|
| 77 | + # Serve clean URLs without .html extension |
| 78 | + location / { |
| 79 | + index index.html; |
| 80 | + try_files $uri $uri.html $uri/ =404; |
| 81 | + } |
| 82 | +
|
| 83 | + # Serve static assets |
| 84 | + location /assets/ { |
| 85 | + expires 30d; |
| 86 | + add_header Cache-Control "public, immutable"; |
| 87 | + } |
| 88 | +
|
| 89 | + location /css/ { |
| 90 | + expires 1w; |
| 91 | + add_header Cache-Control "public, immutable"; |
| 92 | + } |
| 93 | +
|
| 94 | + location /js/ { |
| 95 | + expires 1w; |
| 96 | + add_header Cache-Control "public, immutable"; |
| 97 | + } |
| 98 | +
|
| 99 | + # OTel log ingestion proxy |
| 100 | + location = /v1/logs { |
| 101 | + proxy_pass http://{{ .Values.otel.collectorEndpoint }}/v1/logs; |
| 102 | + proxy_http_version 1.1; |
| 103 | + proxy_set_header Host $host; |
| 104 | + proxy_set_header X-Real-IP $remote_addr; |
| 105 | + proxy_set_header Content-Type $content_type; |
| 106 | + client_max_body_size 64k; |
| 107 | + access_log off; |
| 108 | + } |
| 109 | +
|
| 110 | + # Health endpoints (match probes) |
| 111 | + location = /healthz { |
| 112 | + access_log off; |
| 113 | + add_header Content-Type application/json; |
| 114 | + return 200 '{"status":"HEALTHY"}'; |
| 115 | + } |
| 116 | +
|
| 117 | + location = /healthz/startup { |
| 118 | + access_log off; |
| 119 | + add_header Content-Type application/json; |
| 120 | + return 200 '{"status":"STARTUP_OK"}'; |
| 121 | + } |
| 122 | +
|
| 123 | + location = /healthz/ready { |
| 124 | + access_log off; |
| 125 | + add_header Content-Type application/json; |
| 126 | + return 200 '{"status":"READY_OK"}'; |
| 127 | + } |
| 128 | +
|
| 129 | + # Optional nice to haves |
| 130 | + sendfile on; |
| 131 | + keepalive_timeout 65s; |
| 132 | + } |
0 commit comments