server {
    listen 80;
    #server_name localhost;
    include mime.types;
    types
    {
      application/javascript mjs;
    }
    #charset koi8-r;
    access_log  /var/log/nginx/host.access.log  main;
    error_log  /var/log/nginx/error.log  error;

    # 主应用main-vite
    location /main-vite {
        root /dist;
        add_header Access-Control-Allow-Origin *;
        if ( $request_uri ~* ^.+.(js|css|jpg|png|gif|tif|dpg|jpeg|eot|svg|ttf|woff|json|mp4|rmvb|rm|wmv|avi|3gp)$ ){
        add_header Cache-Control max-age=7776000;
        add_header Access-Control-Allow-Origin *;
        }
        try_files $uri $uri/ /main-vite/index.html;
    }

     # 子应用child-react17
  location /child/react18 {
    root /dist;
    add_header Access-Control-Allow-Origin *;
    if ( $request_uri ~* ^.+.(js|css|jpg|png|gif|tif|dpg|jpeg|eot|svg|ttf|woff|json|mp4|rmvb|rm|wmv|avi|3gp)$ ){
      add_header Cache-Control max-age=7776000;
      add_header Access-Control-Allow-Origin *;
    }
    try_files $uri $uri/ /child/react18/index.html;
  }

    # location / {
    #     root   /usr/share/nginx/html;
    #     index  index.html index.htm index.html.gz;
    #     try_files $uri $uri/ /index.html index.html.gz;
    # }


    # location /api/ {
    #     proxy_pass http://10.0.8.8:8040/;
    # }

    # 代理 WebSocket 连接到 upstream 组定义的服务器
    # location /api/ws/ {
    #     proxy_pass http://10.0.8.8:3001/;  # 代理 WebSocket 请求
    #     proxy_http_version 1.1;  # 必须设置为 1.1，因为 WebSocket 基于 HTTP/1.1
    #     proxy_set_header Upgrade $http_upgrade;  # 转发 Upgrade 头部
    #     proxy_set_header Connection "upgrade";  # 转发 Connection 头部
    #     proxy_set_header Host $host;  # 转发 Host 头部
    #     proxy_set_header X-Real-IP $remote_addr;  # 转发客户端真实 IP
    #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # 转发 X-Forwarded-For 头部
    #     proxy_set_header X-Forwarded-Proto $scheme;  # 转发协议类型，http 或 https
    # }
    # 代理稳定
    # location /static/doc {
    #   charset "utf-8";
    #   alias "/doc";
    #   index index.html index.htm;
    #   autoindex off;
    #   autoindex_exact_size on;
    #   autoindex_localtime on;
    # }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    #开启gzip功能
    gzip on;
    #开启gzip静态压缩功能
    gzip_static on;
    #gzip缓存大小
    gzip_buffers 4 16k;
    #gzip http版本
    gzip_http_version 1.1;
    #gzip 压缩级别 1-10
    gzip_comp_level 5;
    #gzip 压缩类型
    gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    # 是否在http header中添加Vary: Accept-Encoding;
    gzip_vary on;
}
