PortGate

Blueprints · AI & LLMs

Production 20 min · Ollama

Ollama behind the PortGate AI proxy

Binds Ollama to localhost and sends application traffic through the PortGate AI proxy on 127.0.0.1:8787. Daily request and token caps are written into ai_proxy. Binding localhost is the control for the unauthenticated API exposed by CVE-2024-37032. The agent does not check the Ollama package version.

Live config

Baked-in protections

Step 1 · bash

Install the AI proxy

/root/portgate-blueprints/ollama-agent.sh

Uses --mode ai-proxy. A token that only has server ingest cannot post proxy telemetry. The next step writes the caps after this config exists.

#!/bin/sh
set -eu
curl -fsSL "https://example.com/downloads/install.sh" | sh -s -- --token "paste-from-dashboard" --mode ai-proxy --url "https://example.com"

Step 2 · bash

Bind Ollama and point the proxy at it

/root/portgate-blueprints/ollama-bind.sh

The client environment file is what your app should load. The proxy listens on 8787. Ollama stays on 11434.

#!/bin/sh
set -eu
install -d -m 755 /etc/systemd/system/ollama.service.d
cat > /etc/systemd/system/ollama.service.d/bind.conf <<'EOF'
[Service]
Environment=OLLAMA_HOST=127.0.0.1:11434
EOF
cat > /etc/portgate-ollama-client.env <<'EOF'
OLLAMA_HOST=127.0.0.1:11434
OPENAI_BASE_URL=http://127.0.0.1:8787/v1
EOF
chmod 644 /etc/portgate-ollama-client.env
systemctl daemon-reload
systemctl restart ollama || true
if [ -f /opt/portgate/config.json ]; then
  python3 - <<'PY'
import json
from pathlib import Path
path = Path("/opt/portgate/config.json")
data = json.loads(path.read_text(encoding="utf-8"))
proxy = data.get("ai_proxy")
if not isinstance(proxy, dict):
    proxy = {}
proxy["upstream"] = "http://127.0.0.1:11434"
proxy["daily_request_cap"] = int("1000")
proxy["daily_token_cap"] = int("100000")
data["ai_proxy"] = proxy
path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
PY
  systemctl restart portgate-ai-proxy || true
fi