今天部署open-webui时调用模型一直报错SyntaxError: The string did not match the expected pattern.。一开始我以为是我api的问题但当我而使用ip访问就是正常的,这下就把问题锁定在了Nginx反代上,一阵查找后大概锁定了问题的所在, Open-WebUI 使用了 WebSocket 进行模型调用(例如与后端 API 的实时通信),而 Nginx 默认配置没有正确处理 WebSocket 请求,可能会导致语法错误或连接中断。在更改了配置文件后果然解决了问题,下面是我的配置文件。
server {
listen 80;
server_name ai.undefi.me;
# HTTP 重定向到 HTTPS(可选,如果你希望强制使用 HTTPS)
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name ai.undefi.me;
# SSL 配置
ssl_certificate /root/SSL/ai.undefi.me.cer;
ssl_certificate_key /root/SSL/ai.undefi.me.key;
# 上传和缓冲限制
client_max_body_size 50m;
client_body_buffer_size 256k;
# 超时设置
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
proxy_connect_timeout 300s; # 增加超时时间以支持长连接
proxy_read_timeout 300s; # 增加读取超时时间
proxy_send_timeout 300s; # 增加发送超时时间
# 代理缓冲设置
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_ignore_client_abort on;
# 禁用代理缓冲以支持流式响应(如有需要)
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1; # 确保使用 HTTP/1.1
proxy_set_header Upgrade $http_upgrade; # WebSocket 支持
proxy_set_header Connection "upgrade"; # WebSocket 支持
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; # 传递协议信息(http 或 https)
}
}