server {
    listen       80;
    server_name  sj.yougosz.com www.sj.yougosz.com;
    return 301 https://www.sj.yougosz.com$request_uri;
}

server {
    listen 443 ssl;
    server_name sj.yougosz.com;
    include /etc/nginx/conf.d/chanjing/sj.yougosz.com_ssl.common;
    return 301 https://www.sj.yougosz.com$request_uri;
}

server {
        listen  443 ssl;
        server_name  www.sj.yougosz.com;
        include /etc/nginx/conf.d/chanjing/sj.yougosz.com_ssl.common;
        root /cache1/www/sj.yougosz.com/;
        access_log  /var/log/nginx/sj.yougosz.com_access.log main;
        error_log  /var/log/nginx/sj.yougosz.com_error.log;        
        index index.html;
        expires -1;

        client_max_body_size 10240M;
        proxy_read_timeout 1800;  # 秒
        underscores_in_headers on;

        location ~ /(.*)\.txt$ {
            root /cache1/www/sj.yougosz.com/;
        }

        # 优先处理下载页面路径
        location ~* ^/(downloads|downloads\.html)$ {
            try_files /downloads.html /index.html;
        }

        location / {
            try_files $uri $uri/ /index.html;
        }
        
        # 流式接口专用配置
        location = /api/ai_create/submit_stream {

            # 
            access_log /var/log/nginx/sj.yougosz.com_api-access.log main;
            # 禁用缓冲配置
            proxy_buffering      off;          # 完全关闭缓冲
            proxy_buffer_size    16k;          # 最小缓冲区（仅用于头信息）
            proxy_busy_buffers_size 24k;       # 传输中的缓冲区上限
            proxy_max_temp_file_size 0;        # 禁止使用临时文件
            
            # 保持连接配置
            proxy_http_version   1.1;          # 必须使用HTTP/1.1
            proxy_set_header    Connection ""; # 清除默认的close
            chunked_transfer_encoding on;      # 强制分块传输
            
            # 原始代理配置
            include /etc/nginx/conf.d/common.cros.header;
            include /etc/nginx/conf.d/common.cros;
            proxy_pass http://chanying-api-k8s/ai_create/submit_stream;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header access_token $http_access_token;
            
            # 超时优化
            proxy_connect_timeout 60s;    # 后端连接超时
            proxy_send_timeout    600s;   # 发送超时
            proxy_read_timeout    600s;   # 读取超时（保持与全局一致）
        }


        # reverse proxy
        location /api {

        # 日志
            access_log /var/log/nginx/sj.yougosz.com_api-access.log main;
            
            include /etc/nginx/conf.d/common.cros.header;
            include /etc/nginx/conf.d/common.cros;
            rewrite ^/api(.*)$ $1 break;
            proxy_pass http://chanying-api-k8s;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header access_token $http_access_token;        
    }

    # 其他配置
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}