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

Google Colaboratory运行Ollama出现页面异常,该如何修复?

解决Google Colab中Ollama通过ngrok访问异常的方案

问题排查与修复步骤

1. 确认Ollama服务正常启动

  • 查看Colab终端输出,检查ollama serve是否有报错。若出现NVIDIA驱动相关错误,先执行命令验证CUDA环境:
    !nvidia-smi
    
    若驱动显示异常,重启Colab会话后重新安装Ollama。

2. 修正ngrok转发配置

  • 原ngrok命令缺少头部转发参数,导致反向代理时页面请求不匹配,修改启动命令为:
    run(['ngrok', 'http', '--log', 'stderr', '--host-header', 'rewrite', '11434'])
    
    添加--host-header rewrite参数,确保请求头部正确转发到Ollama服务。

3. 先拉取模型再启动服务

  • 空服务状态下Ollama Web UI会无响应,先执行命令拉取一个模型(以Llama 3为例):
    !ollama pull llama3
    
    拉取完成后重新运行启动服务和ngrok的代码。

4. 验证ngrok认证有效性

  • 重新执行ngrok认证命令,确保token配置正确:
    !ngrok config add-authtoken YOUR_NGROK_TOKEN
    
    将YOUR_NGROK_TOKEN替换为你的真实token,避免因认证失败导致转发中断。

5. 改用后台进程启动服务

  • 原异步启动方式可能存在服务启动顺序问题,改用后台运行命令:
    !nohup ollama serve > ollama.log 2>&1 &
    !sleep 5  # 等待服务初始化
    !nohup ngrok http --log stderr --host-header rewrite 11434 > ngrok.log 2>&1 &
    
    执行!curl localhost:11434/api/tags测试本地服务是否正常返回模型列表,再访问ngrok链接。

内容的提问来源于stack exchange,提问作者Sergey Oblasov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 21:53:16