11人参与 • 2025-03-03 • Redis
本地部署deepseek模型,用的ollama管理,内网穿透到公网,在通过nginx反代ollama接口。
proxy_set_header origin http://ip:11434;
proxy_buffering off; proxy_cache off;
proxy_set_header connection ''; proxy_http_version 1.1; chunked_transfer_encoding off;
server { listen 80; server_name 域名; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name 域名; #ssl证书配置 ssl_certificate /opt/nginx/conf/ssl/xxx/fullchain.pem; ssl_certificate_key /opt/nginx/conf/ssl/xxx/key.pem; ssl_session_cache shared:ssl:1m; ssl_session_timeout 5m; ssl_ciphers high:!anull:!md5; ssl_prefer_server_ciphers on; # 反代到 ollama api location /api/ { # ollama 默认端口是 11434 proxy_pass http://服务器ip:11434; # 请求时的origin请求头 proxy_set_header origin http://服务器ip:11434; # 关闭 nginx 的响应缓冲,强制数据实时传输到客户端 proxy_buffering off; # 使用 http/1.1 以支持长连接,避免 http/1.0 的短连接问题 proxy_cache off; # 确保流式传输的实时性 proxy_set_header connection ''; proxy_http_version 1.1; # 关闭 nginx 的分块编码处理(根据实际情况调整) chunked_transfer_encoding off; 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; # 添加 cors 头部 add_header 'access-control-allow-origin' '*' always; add_header 'access-control-allow-methods' 'get, post, options' always; add_header 'access-control-allow-headers' 'dnt,user-agent,x-requested-with,if-modified-since,cache-control,content-type,range,authorization' always; add_header 'access-control-expose-headers' 'content-length,content-range' always; # 处理预检请求 (options) if ($request_method = 'options') { add_header 'access-control-allow-origin' '*'; add_header 'access-control-allow-methods' 'get, post, options'; add_header 'access-control-allow-headers' 'dnt,user-agent,x-requested-with,if-modified-since,cache-control,content-type,range,authorization'; add_header 'access-control-max-age' 1728000; add_header 'content-type' 'text/plain; charset=utf-8'; add_header 'content-length' 0; return 204; } } }
到此这篇关于nginx反代ollama接口跨域无法逐字输出问题的文章就介绍到这了,更多相关nginx反代ollama无法逐字输出内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论