# FuelLog 前端容器用的 nginx 配置 # - 提供 /usr/share/nginx/html 静态资源 # - SPA fallback:所有非 /api 路径都回 /index.html(让 vue-router 接管) # - /api/* 反代到后端容器 api:8080 upstream fuellog_api { server api:8080; keepalive 32; } server { listen 80 default_server; server_name _; # gzip 静态资源 gzip on; gzip_types text/plain text/css application/javascript application/json image/svg+xml application/xml; gzip_min_length 1024; # 静态资源 + SPA fallback root /usr/share/nginx/html; index index.html; # 显式 favicon / manifest / icon location = /favicon.svg { access_log off; expires 30d; } location = /manifest.webmanifest { access_log off; expires 1d; } location ~* ^/pwa-.*\.png$ { access_log off; expires 30d; } # 反代 /api 到后端 location /api/ { proxy_pass http://fuellog_api; 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_set_header Connection ""; # keep-alive proxy_read_timeout 30s; proxy_send_timeout 30s; } # /api/health 这种后端直出,允许直接走 location = /health { proxy_pass http://fuellog_api/health; } # Hashed 静态资源(js/css/woff2)长缓存 location ~* \.(?:js|css|woff2|svg|png|jpg|jpeg|gif|ico)$ { expires 30d; add_header Cache-Control "public, immutable"; try_files $uri =404; } # SPA fallback location / { try_files $uri $uri/ /index.html; } }