worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

error_log  /dev/stderr notice;
pid        /tmp/nginx.pid;


events {
    worker_connections  1024;
}

http {
    proxy_temp_path /tmp/proxy_temp;
    client_body_temp_path /tmp/client_temp;
    fastcgi_temp_path /tmp/fastcgi_temp;
    uwsgi_temp_path /tmp/uwsgi_temp;
    scgi_temp_path /tmp/scgi_temp;

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    access_log  /dev/stdout main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    server {
		listen 8080 default_server;
        root /usr/share/nginx/html/;
        index index.html index.htm;

        location /ws/cluster/v1/ {  # 指定 WebSocket 的连接路径
            proxy_pass http://installer-service.openfuyao-system.svc:9210;  # 替换为实际的 WebSocket 后端地址
            # WebSocket 特有 header 设置
            proxy_set_header Upgrade $http_upgrade;  # 设置 Upgrade 头
            proxy_set_header Connection "Upgrade";  # 设置 Connection 头为 Upgrade
            proxy_http_version 1.1;  # 使用 HTTP/1.1(WebSocket 需要这个)
            # [MOD-5] 传递客户端 Host / 转发头,供 installer-service CheckOrigin 与浏览器 Origin 对齐
            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 X-Forwarded-Host $host;
        }

        #进行一层转发,nginx
        location /rest/cluster/v1/ {
            proxy_pass http://installer-service.openfuyao-system.svc:9210;
        }

        location / {
            try_files $uri /index.html;
        }

        location ~* ^/cluster/.*\.(js|cjs|mjs)$ {
            default_type text/javascript;
            rewrite ^ /dist/cluster.mjs break;
        }

        location ~* \.(js|cjs|mjs)$ {
            default_type text/javascript;
            rewrite ^ /dist/cluster.mjs break;
        }
    }

}