You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu环境下Ollama与Open WebUI连接异常及版本未检测问题求助

问题:Open WebUI无法连接Ollama的解决方法

问题背景

在Ubuntu上通过以下命令部署Open WebUI后,出现「Ollama Version: Not Detected」和「Open WebUI: Server Connection Error」报错:

sudo docker run -d -p 3000:8080 -e OLLAMA_API_BASE_URL=http://host.docker.internal:11434/api --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

关键现象

  • 执行Ollama serve提示端口占用:Error: listen tcp 127.0.0.1:11434: bind: address already in use
  • 本地访问http://127.0.0.1:11434/显示「Ollama is running」,但http://localhost:11434/api返回404,http://localhost:11434/api/version正常返回版本号
  • 本地及同网络设备通过局域网IP访问11434端口均被拒绝
  • Docker容器内访问host.docker.internal/api返回404,访问局域网IP和127.0.0.1均无法连接
  • 已尝试关闭防火墙、修改ollama.service配置、重新部署容器,问题依旧

解决方案

1. 修正Ollama的监听配置

之前的override.conf将环境变量放在了[Unit]段,属于配置错误,需调整到[Service]段:

  • 编辑配置文件:
sudo nano /etc/systemd/system/ollama.service.d/override.conf
  • 修改为以下内容:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_ORIGINS=*"
  • 重新加载systemd并重启Ollama:
sudo systemctl daemon-reload
sudo systemctl restart ollama

2. 验证Ollama监听状态

执行命令确认Ollama在全网卡监听:

ss -tulpn | grep 11434

输出需包含0.0.0.0:11434,而非仅127.0.0.1:11434。

3. 修正Open WebUI的API配置

  • 重新部署容器:调整OLLAMA_API_BASE_URL参数,去掉末尾的/api(Open WebUI会自动拼接路径):
sudo docker stop open-webui
sudo docker rm open-webui
sudo docker run -d -p 3000:8080 -e OLLAMA_API_BASE_URL=http://host.docker.internal:11434 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
  • WebUI后台设置:进入Settings > General,将Ollama api url改为http://host.docker.internal:11434(或宿主机局域网IP,如http://192.168.y.x:11434)

4. 验证连通性

  • 本地测试:执行curl http://192.168.y.x:11434/api/version,应正常返回版本信息
  • 容器内测试:
sudo docker exec -it open-webui bash
curl http://host.docker.internal:11434/api/version

返回版本信息则说明连通正常。

内容的提问来源于stack exchange,提问作者Miguel M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:07:42