Compare commits
No commits in common. "256bafe30df6a7fd76b7661f46f8110366b0a919" and "9f92c09586246592dd7da58adbef5174f80c0f5f" have entirely different histories.
256bafe30d
...
9f92c09586
131
DOCKERHUB.en.md
131
DOCKERHUB.en.md
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
A lightweight reverse proxy for [Ollama](https://ollama.com) that manages API keys with configurable token and request quotas. Incoming requests in OpenAI-compatible format are authenticated, checked against the quota, and forwarded to the configured Ollama server.
|
A lightweight reverse proxy for [Ollama](https://ollama.com) that manages API keys with configurable token and request quotas. Incoming requests in OpenAI-compatible format are authenticated, checked against the quota, and forwarded to the configured Ollama server.
|
||||||
|
|
||||||
|
Ollama does not need to run on the same host — `OLLAMA_URL` can point to any reachable server: the Docker host itself, another machine on the network, or a remote server.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- OpenAI-compatible endpoint (`/v1/chat/completions`, `/v1/models`)
|
- OpenAI-compatible endpoint (`/v1/chat/completions`, `/v1/models`)
|
||||||
@ -19,7 +21,16 @@ A lightweight reverse proxy for [Ollama](https://ollama.com) that manages API ke
|
|||||||
| `8000` | Proxy endpoint (OpenAI API) |
|
| `8000` | Proxy endpoint (OpenAI API) |
|
||||||
| `8001` | Admin API + web interface |
|
| `8001` | Admin API + web interface |
|
||||||
|
|
||||||
All API endpoints require the `ADMIN_PASSWORD` — without a valid token, only the public frontend files (HTML/JS/CSS of the login page) are accessible. The password is therefore the primary protection.
|
Port 8001 must be exposed because the container serves the admin interface directly on this port. All API endpoints require the `ADMIN_PASSWORD` — without a valid token, only the public frontend files (HTML/JS/CSS of the login page) are accessible. The password is therefore the primary protection.
|
||||||
|
|
||||||
|
Additional hardening: binding to `127.0.0.1` restricts access to the local host and prevents direct network access:
|
||||||
|
|
||||||
|
```
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8001:8001" # local access only
|
||||||
|
# or:
|
||||||
|
- "8001:8001" # network-wide, protected by ADMIN_PASSWORD only
|
||||||
|
```
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
@ -31,41 +42,13 @@ All API endpoints require the `ADMIN_PASSWORD` — without a valid token, only t
|
|||||||
| `DATABASE_URL` | `sqlite:///./test.db` | Database connection string (SQLite or PostgreSQL) |
|
| `DATABASE_URL` | `sqlite:///./test.db` | Database connection string (SQLite or PostgreSQL) |
|
||||||
| `PROXY_HOST` | `0.0.0.0` | Proxy bind address |
|
| `PROXY_HOST` | `0.0.0.0` | Proxy bind address |
|
||||||
| `PROXY_PORT` | `8000` | Proxy port |
|
| `PROXY_PORT` | `8000` | Proxy port |
|
||||||
| `ADMIN_HOST` | `0.0.0.0` | Admin API bind address (`127.0.0.1` to restrict to local access) |
|
|
||||||
| `ADMIN_PORT` | `8001` | Admin API port |
|
| `ADMIN_PORT` | `8001` | Admin API port |
|
||||||
| `APP_TZ` | `Europe/Berlin` | Timezone for daily/monthly quota resets |
|
| `APP_TZ` | `Europe/Berlin` | Timezone for daily/monthly quota resets |
|
||||||
| `LOG_FILE` | `logs/usage.log` | Path of the rotating usage log file |
|
| `LOG_FILE` | `logs/usage.log` | Path of the rotating usage log file |
|
||||||
|
|
||||||
## Docker Compose – Ollama on the Host (Linux, recommended)
|
## Docker Compose – External Ollama, SQLite
|
||||||
|
|
||||||
`network_mode: host` gives the container direct access to the host network stack. Ollama runs on the host and is reachable at `localhost:11434` — not visible from outside. The proxy and admin interface are available directly on host ports 8000 and 8001.
|
Use this when Ollama runs outside of Docker — on the Docker host or any other reachable server. Adjust `OLLAMA_URL` accordingly.
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
llmproxy:
|
|
||||||
image: mediaeng/llmproxy:latest
|
|
||||||
container_name: llmproxy
|
|
||||||
restart: unless-stopped
|
|
||||||
network_mode: host
|
|
||||||
env_file: .env
|
|
||||||
volumes:
|
|
||||||
- llmproxy-data:/app/backend
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
llmproxy-data:
|
|
||||||
```
|
|
||||||
|
|
||||||
`.env`:
|
|
||||||
```env
|
|
||||||
ADMIN_PASSWORD=changeme
|
|
||||||
OLLAMA_URL=http://localhost:11434
|
|
||||||
DEFAULT_MODEL=llama3
|
|
||||||
APP_TZ=Europe/Berlin
|
|
||||||
```
|
|
||||||
|
|
||||||
## Docker Compose – Ollama as Container, SQLite
|
|
||||||
|
|
||||||
Ollama and llmproxy run together in Docker. Ollama is not exposed externally.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
@ -74,7 +57,78 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "8001:8001"
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # or http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
# On Linux, add extra_hosts since host.docker.internal is not
|
||||||
|
# available automatically:
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
llmproxy-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – External Ollama, PostgreSQL
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # or http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: llmproxy
|
||||||
|
POSTGRES_USER: llmproxy
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U llmproxy"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama as Container, SQLite
|
||||||
|
|
||||||
|
Ollama and llmproxy run together in Docker, data persisted in a volume.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
@ -107,7 +161,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "8001:8001"
|
- "127.0.0.1:8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
@ -146,6 +200,17 @@ volumes:
|
|||||||
ollama-data:
|
ollama-data:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 8000:8000 \
|
||||||
|
-e ADMIN_PASSWORD=changeme \
|
||||||
|
-e OLLAMA_URL=http://host.docker.internal:11434 \
|
||||||
|
-v llmproxy-data:/app/backend \
|
||||||
|
mediaeng/llmproxy:latest
|
||||||
|
```
|
||||||
|
|
||||||
## Client Configuration
|
## Client Configuration
|
||||||
|
|
||||||
Configure the proxy as an OpenAI-compatible endpoint:
|
Configure the proxy as an OpenAI-compatible endpoint:
|
||||||
|
|||||||
131
DOCKERHUB.md
131
DOCKERHUB.md
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Ein schlanker Reverse-Proxy für [Ollama](https://ollama.com), der API-Keys mit konfigurierbaren Token- und Request-Quoten verwaltet. Eingehende Anfragen im OpenAI-kompatiblen Format werden authentifiziert, auf Quota geprüft und an den konfigurierten Ollama-Server weitergeleitet.
|
Ein schlanker Reverse-Proxy für [Ollama](https://ollama.com), der API-Keys mit konfigurierbaren Token- und Request-Quoten verwaltet. Eingehende Anfragen im OpenAI-kompatiblen Format werden authentifiziert, auf Quota geprüft und an den konfigurierten Ollama-Server weitergeleitet.
|
||||||
|
|
||||||
|
Ollama muss dabei nicht auf demselben Host laufen — `OLLAMA_URL` kann auf jeden erreichbaren Server zeigen, also auf den Docker-Host selbst, einen anderen Rechner im Netzwerk oder einen Remote-Server.
|
||||||
|
|
||||||
## Funktionen
|
## Funktionen
|
||||||
|
|
||||||
- OpenAI-kompatibler Endpunkt (`/v1/chat/completions`, `/v1/models`)
|
- OpenAI-kompatibler Endpunkt (`/v1/chat/completions`, `/v1/models`)
|
||||||
@ -19,7 +21,16 @@ Ein schlanker Reverse-Proxy für [Ollama](https://ollama.com), der API-Keys mit
|
|||||||
| `8000` | Proxy-Endpunkt (OpenAI-API) |
|
| `8000` | Proxy-Endpunkt (OpenAI-API) |
|
||||||
| `8001` | Admin-API + Web-Oberfläche |
|
| `8001` | Admin-API + Web-Oberfläche |
|
||||||
|
|
||||||
Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — ein Zugriff ohne gültiges Token liefert nur die öffentlichen Frontend-Dateien (HTML/JS/CSS der Login-Seite). Das Passwort ist damit die primäre Schutzmaßnahme.
|
Port 8001 muss exposed werden, da der Container die Admin-Oberfläche selbst auf diesem Port ausliefert. Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — ein Zugriff ohne gültiges Token liefert nur die öffentlichen Frontend-Dateien (HTML/JS/CSS der Login-Seite). Das Passwort ist damit die primäre Schutzmaßnahme.
|
||||||
|
|
||||||
|
Zusätzliche Härtung: Portbindung auf `127.0.0.1` beschränkt den Zugriff auf den lokalen Host und verhindert direkten Netzwerkzugriff:
|
||||||
|
|
||||||
|
```
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8001:8001" # nur lokal erreichbar
|
||||||
|
# oder:
|
||||||
|
- "8001:8001" # netzwerkweit, Schutz nur durch ADMIN_PASSWORD
|
||||||
|
```
|
||||||
|
|
||||||
## Umgebungsvariablen
|
## Umgebungsvariablen
|
||||||
|
|
||||||
@ -31,41 +42,13 @@ Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — ein Zugriff ohne gültiges
|
|||||||
| `DATABASE_URL` | `sqlite:///./test.db` | Datenbank-Verbindungsstring (SQLite oder PostgreSQL) |
|
| `DATABASE_URL` | `sqlite:///./test.db` | Datenbank-Verbindungsstring (SQLite oder PostgreSQL) |
|
||||||
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxy |
|
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxy |
|
||||||
| `PROXY_PORT` | `8000` | Port des Proxy |
|
| `PROXY_PORT` | `8000` | Port des Proxy |
|
||||||
| `ADMIN_HOST` | `0.0.0.0` | Bind-Adresse der Admin-API (`127.0.0.1` für lokalen Zugriff) |
|
|
||||||
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
||||||
| `APP_TZ` | `Europe/Berlin` | Zeitzone für Tages-/Monats-Reset der Quoten |
|
| `APP_TZ` | `Europe/Berlin` | Zeitzone für Tages-/Monats-Reset der Quoten |
|
||||||
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
| `LOG_FILE` | `logs/usage.log` | Pfad der rotierenden Nutzungs-Logdatei |
|
||||||
|
|
||||||
## Docker Compose – Ollama auf dem Host (Linux, empfohlen)
|
## Docker Compose – Ollama extern, SQLite
|
||||||
|
|
||||||
`network_mode: host` gibt dem Container direkten Zugriff auf das Host-Netzwerk. Ollama läuft auf dem Host und ist über `localhost:11434` erreichbar — nach außen nicht sichtbar. Proxy und Admin-Oberfläche sind direkt auf den Host-Ports 8000 und 8001 verfügbar.
|
Wenn Ollama außerhalb von Docker läuft — auf dem Docker-Host oder einem anderen erreichbaren Server. `OLLAMA_URL` entsprechend anpassen.
|
||||||
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
llmproxy:
|
|
||||||
image: mediaeng/llmproxy:latest
|
|
||||||
container_name: llmproxy
|
|
||||||
restart: unless-stopped
|
|
||||||
network_mode: host
|
|
||||||
env_file: .env
|
|
||||||
volumes:
|
|
||||||
- llmproxy-data:/app/backend
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
llmproxy-data:
|
|
||||||
```
|
|
||||||
|
|
||||||
`.env`:
|
|
||||||
```env
|
|
||||||
ADMIN_PASSWORD=changeme
|
|
||||||
OLLAMA_URL=http://localhost:11434
|
|
||||||
DEFAULT_MODEL=llama3
|
|
||||||
APP_TZ=Europe/Berlin
|
|
||||||
```
|
|
||||||
|
|
||||||
## Docker Compose – Ollama als Container, SQLite
|
|
||||||
|
|
||||||
Ollama und llmproxy laufen gemeinsam in Docker. Ollama ist nicht nach außen exposed.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
@ -74,7 +57,78 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "8001:8001"
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # oder http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
# Auf Linux extra_hosts ergänzen, da host.docker.internal dort
|
||||||
|
# nicht automatisch verfügbar ist:
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
llmproxy-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama extern, PostgreSQL
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
|
environment:
|
||||||
|
ADMIN_PASSWORD: changeme
|
||||||
|
OLLAMA_URL: http://host.docker.internal:11434 # oder http://<ip>:11434
|
||||||
|
DEFAULT_MODEL: llama3
|
||||||
|
APP_TZ: Europe/Berlin
|
||||||
|
DATABASE_URL: postgresql://llmproxy:secret@db:5432/llmproxy
|
||||||
|
volumes:
|
||||||
|
- llmproxy-data:/app/backend
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
# extra_hosts:
|
||||||
|
# - "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: llmproxy
|
||||||
|
POSTGRES_USER: llmproxy
|
||||||
|
POSTGRES_PASSWORD: secret
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U llmproxy"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose – Ollama als Container, SQLite
|
||||||
|
|
||||||
|
Ollama und llmproxy laufen gemeinsam in Docker, Daten in einem Volume.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
llmproxy:
|
||||||
|
image: mediaeng/llmproxy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
- "127.0.0.1:8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
@ -107,7 +161,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
- "8001:8001"
|
- "127.0.0.1:8001:8001"
|
||||||
environment:
|
environment:
|
||||||
ADMIN_PASSWORD: changeme
|
ADMIN_PASSWORD: changeme
|
||||||
OLLAMA_URL: http://ollama:11434
|
OLLAMA_URL: http://ollama:11434
|
||||||
@ -146,6 +200,17 @@ volumes:
|
|||||||
ollama-data:
|
ollama-data:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Schnellstart
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-p 8000:8000 \
|
||||||
|
-e ADMIN_PASSWORD=changeme \
|
||||||
|
-e OLLAMA_URL=http://host.docker.internal:11434 \
|
||||||
|
-v llmproxy-data:/app/backend \
|
||||||
|
mediaeng/llmproxy:latest
|
||||||
|
```
|
||||||
|
|
||||||
## Client-Konfiguration
|
## Client-Konfiguration
|
||||||
|
|
||||||
Den Proxy als OpenAI-kompatibler Endpunkt konfigurieren:
|
Den Proxy als OpenAI-kompatibler Endpunkt konfigurieren:
|
||||||
|
|||||||
79
README.md
79
README.md
@ -1,6 +1,6 @@
|
|||||||
# Ollama Proxy mit API-Keys und Quotas
|
# Ollama Proxy mit API-Keys und Quotas
|
||||||
|
|
||||||
Ollama bietet von sich aus keine Authentifizierung — wer die API erreicht, kann sie nutzen. Dieses Projekt löst das Problem: Ollama bleibt an `localhost` gebunden und ist von außen nicht erreichbar. Vorgeschaltet läuft ein Proxy (Port 8000), der jeden Request auf einen gültigen API-Key prüft und optional Token- sowie Request-Quoten pro Key durchsetzt. Eine Web-Admin-Oberfläche (Port 8001) erlaubt das Verwalten von Keys, Quoten und Ollama-Einstellungen.
|
Ein Reverse-Proxy für Ollama mit API-Key-Authentifizierung, Quota-Management und Web-Admin-Oberfläche.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ Ollama bietet von sich aus keine Authentifizierung — wer die API erreicht, kan
|
|||||||
- Admin-Oberfläche passwortgeschützt (`ADMIN_PASSWORD`) — alle API-Endpunkte erfordern den Token
|
- Admin-Oberfläche passwortgeschützt (`ADMIN_PASSWORD`) — alle API-Endpunkte erfordern den Token
|
||||||
- API-Keys als SHA-256-Hash in der DB — Plaintext nur einmalig bei Erstellung
|
- API-Keys als SHA-256-Hash in der DB — Plaintext nur einmalig bei Erstellung
|
||||||
- Quota-Check atomar mit `SELECT FOR UPDATE` (kein TOCTOU-Race)
|
- Quota-Check atomar mit `SELECT FOR UPDATE` (kein TOCTOU-Race)
|
||||||
- Admin-Port 8001 über `ADMIN_HOST=127.0.0.1` auf lokalen Zugriff beschränkbar
|
- Port 8001 kann optional auf `127.0.0.1` gebunden werden (zusätzliche Härtung)
|
||||||
|
|
||||||
## Konfiguration
|
## Konfiguration
|
||||||
|
|
||||||
@ -29,7 +29,6 @@ Ollama bietet von sich aus keine Authentifizierung — wer die API erreicht, kan
|
|||||||
ADMIN_PASSWORD=change-me
|
ADMIN_PASSWORD=change-me
|
||||||
PROXY_HOST=0.0.0.0
|
PROXY_HOST=0.0.0.0
|
||||||
PROXY_PORT=8000
|
PROXY_PORT=8000
|
||||||
ADMIN_HOST=0.0.0.0
|
|
||||||
ADMIN_PORT=8001
|
ADMIN_PORT=8001
|
||||||
DATABASE_URL=sqlite:///./test.db
|
DATABASE_URL=sqlite:///./test.db
|
||||||
OLLAMA_URL=http://localhost:11434
|
OLLAMA_URL=http://localhost:11434
|
||||||
@ -43,7 +42,6 @@ LOG_FILE=logs/usage.log
|
|||||||
| `ADMIN_PASSWORD` | — | Passwort für die Admin-Oberfläche (**Pflicht**) |
|
| `ADMIN_PASSWORD` | — | Passwort für die Admin-Oberfläche (**Pflicht**) |
|
||||||
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxys |
|
| `PROXY_HOST` | `0.0.0.0` | Bind-Adresse des Proxys |
|
||||||
| `PROXY_PORT` | `8000` | Port des Proxys |
|
| `PROXY_PORT` | `8000` | Port des Proxys |
|
||||||
| `ADMIN_HOST` | `0.0.0.0` | Bind-Adresse der Admin-API (z. B. `127.0.0.1` für lokalen Zugriff) |
|
|
||||||
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
| `ADMIN_PORT` | `8001` | Port der Admin-API |
|
||||||
| `DATABASE_URL` | `sqlite:///./test.db` | DB-Verbindungsstring (SQLite oder PostgreSQL) |
|
| `DATABASE_URL` | `sqlite:///./test.db` | DB-Verbindungsstring (SQLite oder PostgreSQL) |
|
||||||
| `OLLAMA_URL` | `http://localhost:11434` | Adresse der Ollama-Instanz (auch in der UI änderbar) |
|
| `OLLAMA_URL` | `http://localhost:11434` | Adresse der Ollama-Instanz (auch in der UI änderbar) |
|
||||||
@ -88,13 +86,7 @@ Admin-Oberfläche: `http://localhost:5173`
|
|||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
Zieht das Image von DockerHub und lädt Variablen aus `.env`.
|
Zieht das Image von DockerHub, lädt Variablen aus `.env` und verwendet die lokale SQLite-Datenbank. Weitere Compose-Varianten (PostgreSQL, Ollama als Container) siehe `DOCKERHUB.md`.
|
||||||
|
|
||||||
Das Setup verwendet `network_mode: host`: Der Container teilt den Netzwerkstack des Hosts, statt ein eigenes virtuelles Netzwerk zu bekommen. Das ist hier aus zwei Gründen die richtige Wahl:
|
|
||||||
|
|
||||||
1. **Ollama soll nicht von außen erreichbar sein.** Ollama läuft auf dem Host und ist an `127.0.0.1:11434` gebunden — nur lokal erreichbar. Mit einem eigenen Container-Netzwerk (Bridge-Mode) wäre `localhost` aus Sicht des Containers der Container selbst, nicht der Host. Die übliche Alternative (`host.docker.internal` + `extra_hosts`) ist auf Linux unzuverlässig.
|
|
||||||
|
|
||||||
2. **Kein doppeltes Port-Mapping nötig.** Mit `network_mode: host` sind Port 8000 und 8001 direkt auf dem Host verfügbar, ohne `ports:`-Einträge in der Compose-Datei.
|
|
||||||
|
|
||||||
### Image selbst bauen und pushen
|
### Image selbst bauen und pushen
|
||||||
|
|
||||||
@ -106,68 +98,15 @@ Das Script zeigt den aktuellen Git-Tag, bietet an einen neuen zu setzen, baut da
|
|||||||
|
|
||||||
### Port 8001 (Admin)
|
### Port 8001 (Admin)
|
||||||
|
|
||||||
Alle Admin-Endpunkte erfordern das `ADMIN_PASSWORD` — der Token ist der primäre Schutz. Für zusätzliche Härtung lässt sich die Admin-API auf lokalen Zugriff beschränken:
|
Port 8001 muss exposed werden, da der Container die Admin-Oberfläche auf diesem Port ausliefert. Alle API-Endpunkte erfordern das `ADMIN_PASSWORD` — der Token ist der primäre Schutz. Optionale zusätzliche Härtung: Bindung auf `127.0.0.1`:
|
||||||
|
|
||||||
```env
|
```yaml
|
||||||
ADMIN_HOST=127.0.0.1
|
ports:
|
||||||
|
- "127.0.0.1:8001:8001" # nur lokal
|
||||||
|
# oder:
|
||||||
|
- "8001:8001" # netzwerkweit, Schutz durch ADMIN_PASSWORD
|
||||||
```
|
```
|
||||||
|
|
||||||
Bei `network_mode: host` (Produktions-Standard) ist das die einzig wirksame Methode — Docker-Port-Mapping greift dort nicht.
|
|
||||||
|
|
||||||
### HTTPS via Reverse-Proxy (ungetestet)
|
|
||||||
|
|
||||||
Wer Proxy und Admin-Oberfläche per HTTPS bereitstellen will, kann einen weiteren Reverse-Proxy (z. B. Nginx oder Caddy) vorschalten. Bei `network_mode: host` lauschen beide Dienste direkt auf dem Host, Nginx/Caddy proxyen auf `localhost`.
|
|
||||||
|
|
||||||
**Caddy** (empfohlen — automatisches TLS via Let's Encrypt):
|
|
||||||
|
|
||||||
```
|
|
||||||
llm.example.com {
|
|
||||||
reverse_proxy localhost:8000 {
|
|
||||||
flush_interval -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
llm-admin.example.com {
|
|
||||||
reverse_proxy localhost:8001
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Nginx** (mit Certbot-Zertifikaten):
|
|
||||||
|
|
||||||
```nginx
|
|
||||||
server {
|
|
||||||
listen 443 ssl;
|
|
||||||
server_name llm.example.com;
|
|
||||||
|
|
||||||
ssl_certificate /etc/letsencrypt/live/llm.example.com/fullchain.pem;
|
|
||||||
ssl_certificate_key /etc/letsencrypt/live/llm.example.com/privkey.pem;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:8000;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_buffering off; # nötig für Streaming
|
|
||||||
proxy_cache off;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 443 ssl;
|
|
||||||
server_name llm-admin.example.com;
|
|
||||||
|
|
||||||
ssl_certificate /etc/letsencrypt/live/llm-admin.example.com/fullchain.pem;
|
|
||||||
ssl_certificate_key /etc/letsencrypt/live/llm-admin.example.com/privkey.pem;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://127.0.0.1:8001;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Clients konfigurieren dann `https://llm.example.com/v1` als Base URL.
|
|
||||||
|
|
||||||
## Proxy-Endpunkte (Port 8000)
|
## Proxy-Endpunkte (Port 8000)
|
||||||
|
|
||||||
Alle Endpunkte erfordern einen gültigen API-Key im `Authorization`-Header.
|
Alle Endpunkte erfordern einen gültigen API-Key im `Authorization`-Header.
|
||||||
|
|||||||
@ -5,24 +5,17 @@ cd "$(dirname "$0")"
|
|||||||
IMAGE=mediaeng/llmproxy
|
IMAGE=mediaeng/llmproxy
|
||||||
PLATFORM=linux/arm64
|
PLATFORM=linux/arm64
|
||||||
|
|
||||||
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
|
CURRENT=$(git describe --tags --always)
|
||||||
HEAD_TAG=$(git tag --points-at HEAD | head -1)
|
if [ -z "$CURRENT" ]; then
|
||||||
|
echo "Fehler: git describe liefert kein Ergebnis"
|
||||||
if [ -n "$HEAD_TAG" ]; then
|
exit 1
|
||||||
echo "HEAD bereits getaggt: $HEAD_TAG"
|
|
||||||
read -rp "Neuer Tag [${HEAD_TAG}]: " INPUT
|
|
||||||
VERSION="${INPUT:-$HEAD_TAG}"
|
|
||||||
else
|
|
||||||
echo "Letzter Tag: ${LAST_TAG:-kein Tag}"
|
|
||||||
read -rp "Neuer Tag: " INPUT
|
|
||||||
if [ -z "$INPUT" ]; then
|
|
||||||
echo "Kein Tag angegeben, breche ab."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
VERSION="$INPUT"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$VERSION" != "$HEAD_TAG" ]; then
|
echo "Aktueller Tag: $CURRENT"
|
||||||
|
read -rp "Neuer Tag [${CURRENT}]: " INPUT
|
||||||
|
VERSION="${INPUT:-$CURRENT}"
|
||||||
|
|
||||||
|
if [ "$VERSION" != "$CURRENT" ]; then
|
||||||
git tag "$VERSION"
|
git tag "$VERSION"
|
||||||
git push origin "$VERSION"
|
git push origin "$VERSION"
|
||||||
echo "Tag '$VERSION' gesetzt und gepusht."
|
echo "Tag '$VERSION' gesetzt und gepusht."
|
||||||
|
|||||||
@ -10,7 +10,7 @@ uvicorn main:app \
|
|||||||
PROXY_PID=$!
|
PROXY_PID=$!
|
||||||
|
|
||||||
uvicorn admin:app \
|
uvicorn admin:app \
|
||||||
--host "${ADMIN_HOST:-0.0.0.0}" \
|
--host "0.0.0.0" \
|
||||||
--port "${ADMIN_PORT:-8001}" &
|
--port "${ADMIN_PORT:-8001}" &
|
||||||
ADMIN_PID=$!
|
ADMIN_PID=$!
|
||||||
|
|
||||||
|
|||||||
@ -40,14 +40,13 @@ def main():
|
|||||||
|
|
||||||
proxy_host = os.environ.get('PROXY_HOST', '0.0.0.0')
|
proxy_host = os.environ.get('PROXY_HOST', '0.0.0.0')
|
||||||
proxy_port = os.environ.get('PROXY_PORT', '8000')
|
proxy_port = os.environ.get('PROXY_PORT', '8000')
|
||||||
admin_host = os.environ.get('ADMIN_HOST', '127.0.0.1')
|
|
||||||
admin_port = os.environ.get('ADMIN_PORT', '8001')
|
admin_port = os.environ.get('ADMIN_PORT', '8001')
|
||||||
|
|
||||||
print('Initialisiere Datenbank...')
|
print('Initialisiere Datenbank...')
|
||||||
subprocess.run([str(python), 'init_db.py'], cwd=backend, check=True)
|
subprocess.run([str(python), 'init_db.py'], cwd=backend, check=True)
|
||||||
|
|
||||||
print(f'Starte Proxy → http://{proxy_host}:{proxy_port}')
|
print(f'Starte Proxy → http://{proxy_host}:{proxy_port}')
|
||||||
print(f'Starte Admin-API → http://{admin_host}:{admin_port}')
|
print(f'Starte Admin-API → http://127.0.0.1:{admin_port}')
|
||||||
print('Starte Frontend → http://localhost:5173')
|
print('Starte Frontend → http://localhost:5173')
|
||||||
|
|
||||||
env = {**os.environ, 'PYTHONUNBUFFERED': '1'}
|
env = {**os.environ, 'PYTHONUNBUFFERED': '1'}
|
||||||
@ -60,7 +59,7 @@ def main():
|
|||||||
), 'Proxy ', '34'), # blau
|
), 'Proxy ', '34'), # blau
|
||||||
(subprocess.Popen(
|
(subprocess.Popen(
|
||||||
[str(python), '-m', 'uvicorn', 'admin:app', '--reload',
|
[str(python), '-m', 'uvicorn', 'admin:app', '--reload',
|
||||||
'--host', admin_host, '--port', admin_port],
|
'--host', '127.0.0.1', '--port', admin_port],
|
||||||
cwd=backend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
cwd=backend, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env,
|
||||||
), 'Admin ', '33'), # gelb
|
), 'Admin ', '33'), # gelb
|
||||||
(subprocess.Popen(
|
(subprocess.Popen(
|
||||||
|
|||||||
8
start.sh
8
start.sh
@ -21,7 +21,6 @@ fi
|
|||||||
|
|
||||||
PROXY_HOST=${PROXY_HOST:-0.0.0.0}
|
PROXY_HOST=${PROXY_HOST:-0.0.0.0}
|
||||||
PROXY_PORT=${PROXY_PORT:-8000}
|
PROXY_PORT=${PROXY_PORT:-8000}
|
||||||
ADMIN_HOST=${ADMIN_HOST:-127.0.0.1}
|
|
||||||
ADMIN_PORT=${ADMIN_PORT:-8001}
|
ADMIN_PORT=${ADMIN_PORT:-8001}
|
||||||
FRONTEND_PORT=5173
|
FRONTEND_PORT=5173
|
||||||
|
|
||||||
@ -61,8 +60,9 @@ cd backend
|
|||||||
python3 -m uvicorn main:app --reload --host "$PROXY_HOST" --port "$PROXY_PORT" &
|
python3 -m uvicorn main:app --reload --host "$PROXY_HOST" --port "$PROXY_PORT" &
|
||||||
PIDS+=($!)
|
PIDS+=($!)
|
||||||
|
|
||||||
echo "Starte Admin-API auf ${ADMIN_HOST}:${ADMIN_PORT}..."
|
# Admin-API immer nur lokal erreichbar (Host nicht konfigurierbar)
|
||||||
python3 -m uvicorn admin:app --reload --host "$ADMIN_HOST" --port "$ADMIN_PORT" &
|
echo "Starte Admin-API auf 127.0.0.1:${ADMIN_PORT}..."
|
||||||
|
python3 -m uvicorn admin:app --reload --host 127.0.0.1 --port "$ADMIN_PORT" &
|
||||||
PIDS+=($!)
|
PIDS+=($!)
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ PIDS+=($!)
|
|||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
echo "Backend läuft (Port $PROXY_PORT)"
|
echo "Backend läuft (Port $PROXY_PORT)"
|
||||||
echo "Admin-API läuft (${ADMIN_HOST}:${ADMIN_PORT})"
|
echo "Admin-API läuft (Port $ADMIN_PORT, nur lokal)"
|
||||||
echo "Admin-Oberfläche: http://localhost:$FRONTEND_PORT"
|
echo "Admin-Oberfläche: http://localhost:$FRONTEND_PORT"
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user