Blame view

script/docker-compose/nginx/default.conf 1.95 KB
ee2cfb9c   YunaiV   feat(deploy): 更新 ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  # 前端静态资源 + 同源反向代理到 yudao-server
  # 浏览器只访问本 Nginx,前端 API 地址使用同源路径 /admin-api,不要写容器名
  
  map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
  }
  
  server {
      listen 80;
      server_name _;
  
      root /usr/share/nginx/html;
      index index.html;
  
      # 与后端 spring.servlet.multipart.max-request-size 保持一致
      client_max_body_size 32m;
  
      gzip on;
      gzip_min_length 1k;
      gzip_comp_level 5;
      gzip_types text/plain text/css application/javascript application/json application/xml image/svg+xml;
      gzip_vary on;
  
      # 使用 Docker 内置 DNS 动态解析服务名,后端容器重建后无需重启 Nginx
      resolver 127.0.0.11 valid=10s ipv6=off;
      set $yudao_backend http://yudao-server:48080;
  
      # 前端路由(history 模式)回退到 index.html
      location / {
          try_files $uri $uri/ /index.html;
      }
  
      location = /index.html {
          add_header Cache-Control "no-cache";
      }
  
      # 管理后台 API、用户 App API
      location ~ ^/(admin-api|app-api)/ {
          proxy_pass $yudao_backend;
          proxy_http_version 1.1;
          proxy_set_header Host $http_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 "";
          # 流式响应(SSE)不缓冲
          proxy_buffering off;
          proxy_read_timeout 300s;
      }
  
      # WebSocket
      location /infra/ws {
          proxy_pass $yudao_backend;
          proxy_http_version 1.1;
          proxy_set_header Host $http_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 Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
          proxy_read_timeout 3600s;
      }
  }