user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
  worker_connections  1024;
}

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;

  # 上游后端定义
  upstream picture_backend {
    server smile-picture-backend:8096;
  }

  server {
      listen       80;
      server_name  _;

      root /usr/share/nginx/html;
      index  index.html;

      # ---------- REST API 代理 ----------
      location /api/ {
          proxy_pass        http://picture_backend;
          proxy_set_header  Host       $host;
          proxy_set_header  X-Real-IP  $remote_addr;
          client_max_body_size 10M;  # 允许上传 10MB
          # 添加代理超时设置（单位：秒）
          proxy_connect_timeout 600s;
          proxy_send_timeout 600s;
          proxy_read_timeout 600s;
      }

      # ---------- WebSocket 代理 ----------
      location /api/ws/ {
          proxy_pass              http://picture_backend;
          proxy_http_version      1.1;
          proxy_set_header        Upgrade            $http_upgrade;
          proxy_set_header        Connection         "upgrade";
          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_buffering         off;
          proxy_read_timeout      86400s;
      }

      # ---------- 前端路由兼容 ----------
      # HTML5 history-mode：找不到文件时回退到 index.html 交给前端渲染
      location / {
          try_files $uri $uri/ /index.html;
      }
  }
}
