# nginx config ของ farm-planning (ถูก envsubst ตอน start) # ตัวแปรที่ใช้: ${WEB_CONTAINER_PORT} ${API_CONTAINER_PORT} # หมายเหตุ: official nginx image แทนค่าเฉพาะ env var ที่มีอยู่จริง — $uri/$host ไม่ถูกแตะ server { listen ${WEB_CONTAINER_PORT}; listen [::]:${WEB_CONTAINER_PORT}; server_name _; root /app; index index.html; charset utf-8; gzip on; gzip_comp_level 6; gzip_min_length 1024; gzip_proxied any; gzip_types text/plain text/css application/javascript application/json image/svg+xml application/manifest+json; # ---- health ---- location = /healthz { access_log off; add_header Content-Type text/plain always; return 200 "ok\n"; } # ---- API (proxy ไปคอนเทนเนอร์ api) ---- location /api/ { proxy_pass http://api:${API_CONTAINER_PORT}; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_connect_timeout 5s; proxy_read_timeout 30s; add_header Cache-Control "no-store" always; } # ---- ไฟล์ที่ต้องได้ของใหม่ทุกครั้ง (SW, version, shell) ---- location = /sw.js { add_header Cache-Control "no-cache, must-revalidate" always; try_files $uri =404; } location = /app/version.json { add_header Cache-Control "no-cache, must-revalidate" always; try_files $uri =404; } location = /index.html { add_header Cache-Control "no-cache, must-revalidate" always; } # ---- JSON ข้อมูล: ให้ cache สั้น ๆ (stale-while-revalidate ที่ฝั่ง SW อยู่แล้ว) ---- location /data/ { expires 5m; add_header Cache-Control "public, max-age=300" always; try_files $uri =404; } # ---- asset: cache ยาว ---- location ~* \.(css|js|png|jpe?g|gif|svg|ico|woff2?|webp)$ { expires 30d; add_header Cache-Control "public, max-age=2592000, immutable" always; try_files $uri =404; } # ---- SPA (hash router): ทุก path ที่ไม่ใช่ไฟล์ ให้ส่ง index.html ---- location / { add_header Cache-Control "no-cache, must-revalidate" always; try_files $uri $uri/ /index.html; } }