Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Your local Ollama has no API key. Here’s how to require one (Caddy or nginx) and still use Open WebUI, n8n and OpenAI clients

Описание и применение

Рецепт позволяет защитить локальный сервер Ollama, требуя токен в заголовке Authorization: Bearer через обратный прокси Caddy или nginx, сохраняя совместимость с клиентами OpenAI‑стиля.

Задача

Ollama’s local API on port 11434 is unauthenticated, exposing GPU resources to any host that can reach the port when OLLAMA_HOST is set to 0.0.0.0.

Результат

The recipe enables secure access to a local Ollama instance by requiring a bearer token via a reverse proxy, preventing unauthorized use while maintaining compatibility with existing OpenAI‑style clients.

Рабочий процесс

  • Generate a 32‑byte hex key with openssl rand -hex 32
  • Configure Caddy or nginx to listen on a public domain and proxy to 127.0.0.1:11434
  • Set the proxy to match the Authorization header exactly and reject others with 401
  • Strip the Authorization header before forwarding to Ollama
  • Test the proxy with curl to confirm 401 on missing key and success on correct key
  • Verify that external access to 127.0.0.1:11434 fails when the proxy is active
  • Configure n8n, Open WebUI, OpenAI SDK, and ollama‑python to use the proxy URL and the generated key

Доказательства

The local API at http://localhost:11434 does not require authentication.

Источник

From then on, anyone who can reach port 11434 can run prompts on your GPU and pull, create or delete models.

Источник

The Caddyfile now holds a secret, so make it readable only by root and Caddy.

Источник

  • Дата записи: 2026-10-12T17:41:42.972Z