

























127.0.0.1:11434,无密码,公网暴露极危险。http://你的域名/ollama → 鉴权 → 转发到本地 Ollama;OpenClaw 带 Key 远程连接。server {
listen 80;
server_name 你的域名; # 换成你的域名或公网IP
# 核心:/ollama/ 路径反向代理+鉴权
location /ollama/ {
# 1. 预检请求放行(跨域)
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 Authorization,Content-Type;
return 204;
}
# 2. Bearer Key 校验(关键!)
set $auth $http_authorization;
if ($auth != "Bearer ollamakey") { # 密钥:ollamakey,可自定义
add_header WWW-Authenticate 'Bearer realm="Ollama API"';
return 401; # 鉴权失败返回401
}
# 3. 反向代理到本地 Ollama
proxy_pass http://127.0.0.1:11434/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
}
}
#if ($http_authorization != "Bearer E4613") { # return 401 Unauthorized; #} # 反向代理到 11434 #location /ollama/ { # 反向代理 #proxy_pass http://127.0.0.1:11434/; #proxy_set_header Host $host; #proxy_set_header X-Real-IP $remote_addr; #proxy_http_version 1.1; #proxy_set_header Authorization ""; # 清除转发时的 Authorization #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header X-Forwarded-Proto $scheme; #} # 放行模型列表API location = /ollama/api/tags { proxy_pass http://127.0.0.1:11434/api/tags; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location = /ollama/api/show { proxy_pass http://127.0.0.1:11434/api/show; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # 其他所有 /ollama/ 下的请求都需要鉴权 location /ollama/ { # 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 Authorization,Content-Type; return 204; } # 鉴权 if ($http_authorization != "Bearer E43") { add_header WWW-Authenticate 'Bearer realm="Ollama API"'; return 401; } proxy_pass http://127.0.0.1:11434/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_http_version 1.1; proxy_set_header Authorization ""; }
ollamakey 换成你的强密码,例如 Bearer E46xxxxA3。nginx -t # 检查配置,必须显示 success
systemctl restart nginx
curl -i \
-H "Authorization: Bearer ollamakey" \
http://你的域名/ollama/api/tags
/ollama/api/tags)。| 配置项 | 填写内容 |
|---|---|
| Base URL | http://你的域名/ollama(无 /v1,末尾无斜杠) |
| API Key | ollamakey(Bearer 后的值) |
| 自定义请求头 | Authorization: Bearer ollamakey(头名 / 值分开填) |
填本地存在的模型,如 qwen3:7b、gemma4:e4b(用 ollama list 查看)。
/v1、请求头没带对。Bearerollamakey)、多引号、大小写错误。http://域名:11434 或 /ollama/v1。Authorization)。location /ollama/ + Bearer 鉴权,安全暴露 Ollama。curl -H "Authorization: Bearer 密钥" 地址,通了再配 OpenClaw。/ollama、Key 填密钥、头带 Authorization。要不要我把这套配置整理成一份可直接复制的 Nginx 配置文件和 OpenClaw 导入模板,你直接粘贴就能用?
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。