upstream myapi {
    ip_hash;
    server 127.0.0.1:48080;
}

server {
    listen          80;
    server_name     ai.api.daoguyujia.com api.daogu.ai;
    client_max_body_size 500M;

    location ^~ /.well-known/acme-challenge/ {
        root /home/webroot;
        allow all;
    }

    location / {
        proxy_pass http://myapi;
        proxy_http_version 1.1;
        proxy_connect_timeout 4s;
        proxy_read_timeout 60s;
        proxy_send_timeout 12s;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
    }

    # 接口开放监听 (SSE)
    location /api/sse/ {
        proxy_pass http://myapi/api/sse/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_read_timeout 300s;
        proxy_send_timeout 300s;
        proxy_buffering off;
        proxy_cache off;
        proxy_set_header Connection "";
    }

}

server {
    listen       443 ssl;
    server_name  ai.api.daoguyujia.com api.daogu.ai;

    ssl_certificate      /root/.acme.sh/ai.api.daoguyujia.com/fullchain.cer;
    ssl_certificate_key  /root/.acme.sh/ai.api.daoguyujia.com/ai.api.daoguyujia.com.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location / {
        proxy_pass http://myapi;
        proxy_http_version 1.1;
        proxy_connect_timeout 4s;
        proxy_read_timeout 60s;
        proxy_send_timeout 12s;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
    }

    # 接口开放监听 (SSE)
    location /api/sse/ {
        proxy_pass http://myapi/api/sse/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_read_timeout 300s;
        proxy_send_timeout 300s;
        proxy_buffering off;
        proxy_cache off;
        proxy_set_header Connection "";
    }

}
