nginx.conf 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. server {
  2. listen 80;
  3. server_name _;
  4. # Gzip compression for API responses and static assets
  5. gzip on;
  6. gzip_types application/json text/plain text/css application/javascript;
  7. gzip_min_length 1000;
  8. gzip_comp_level 6;
  9. # 前端静态文件
  10. location / {
  11. root /usr/share/nginx/html;
  12. index index.html;
  13. try_files $uri $uri/ /index.html;
  14. # Cache static assets
  15. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf)$ {
  16. expires 7d;
  17. add_header Cache-Control "public, max-age=604800, immutable";
  18. }
  19. }
  20. # Health check (no proxy)
  21. location /ping {
  22. proxy_pass http://api:8080;
  23. proxy_connect_timeout 5s;
  24. proxy_read_timeout 5s;
  25. }
  26. # API 代理(含 WebSocket)
  27. location /api/ {
  28. proxy_pass http://api:8080;
  29. proxy_http_version 1.1;
  30. proxy_set_header Upgrade $http_upgrade;
  31. proxy_set_header Connection "upgrade";
  32. proxy_set_header Host $host;
  33. proxy_set_header X-Real-IP $remote_addr;
  34. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  35. proxy_read_timeout 300s;
  36. proxy_send_timeout 300s;
  37. # Larger buffer for big API responses
  38. proxy_buffer_size 16k;
  39. proxy_buffers 8 32k;
  40. # No caching for API
  41. add_header Cache-Control "no-cache, no-store, must-revalidate";
  42. }
  43. }