Skip to content
All guides

Guide · Deploy

Run a private LLM on a single VPS

One server running Docker Compose, with automatic HTTPS and an API key in front of vLLM on a GPU or llama.cpp on a CPU. We checked every image tag, flag and config key against the official docs on 23 November 2026.

Suraj Malthumkar12 min readFacts, prices and versions checked November 23, 2026
vps · docker compose · caddy → vllm
Private LLM on a single VPSYour apps call one server over HTTPS. A firewall admits only port 443. Caddy terminates TLS and checks the API key, then forwards to vLLM or llama.cpp on a private Docker network. The model server loads its weights from local disk and exposes metrics that Prometheus scrapes for Grafana dashboards.Your VPS · Ubuntu + DockerPrivate Docker networksends HTTPS + keyforwardsload at startscrape /metricsYour apps & agentsOpenAI SDKFirewallonly 443 + SSHCaddyTLS · API key checkvLLM or llama.cppOpenAI-compatible /v1Prometheus + Grafanalatency · tokens/s · GPUModel fileslocal NVMe · pinned
  1. Step 1: Your app calls the endpoint. Agents and apps send an HTTPS request with an API key to your own domain, using the OpenAI SDK they already have. The firewall admits port 443 and SSH from your IP, nothing else.
  2. Step 2: Caddy terminates TLS. Caddy gets and renews the certificate automatically, rejects requests without the right key, and forwards the rest to the model server over a private Docker network. The model server never listens on a public port.
  3. Step 3: The model answers. On a GPU server, vLLM batches concurrent requests and streams tokens back. On a CPU-only VPS, llama.cpp runs a small quantized model: fine for internal tools, too slow for customer traffic.
  4. Step 4: Weights come from local disk. The model is downloaded once at a pinned revision and checksummed. At start-up the server reads it from local NVMe, so nothing at runtime depends on the internet.
  5. Step 5: Metrics and alerts. Prometheus scrapes the model server's metrics endpoint and Grafana shows latency, throughput, errors and GPU memory. Prompts and outputs are not logged unless you decide they should be.
Reference architecture · A single VPS

This guide builds the setup in the diagram above: an OpenAI-compatible endpoint on your own domain, served over HTTPS, guarded by an API key and monitored by Prometheus and Grafana. Each setup section names the diagram step it builds. You need an Ubuntu 24.04 LTS server with sudo, a domain whose A record points at it, and SSH key access.

Choose the hardware

A GPU server for real traffic. Rent a GPU for anything customers will use. Hetzner lists four GPU servers (checked 23 November 2026, excluding VAT):

ServerGPUMonthlyHourlySetupLocation
GEX451× RTX PRO 4000 Blackwell SFF, 24 GB€214€0.3429€209Helsinki
GEX631× RTX PRO 6000 Blackwell Max-Q, 96 GB€999€1.6009€999Helsinki
GEX1311× RTX PRO 6000 Blackwell Max-Q, 96 GBfrom €1,499€2.4022€1,499Helsinki, Falkenstein
GEX4304× RTX PRO 6000 Blackwell Max-Q, 384 GB€3,599€5.7676€3,599Helsinki

The page doesn't state a monthly cap or minimum term for hourly billing, so confirm before you rely on it. The GEX44 and GEX130 that older guides name are no longer listed. Any provider works if you get root access and an NVIDIA GPU.

A CPU-only VPS for light internal use. Without a GPU, memory bandwidth sets the speed: tokens per second is at most roughly RAM bandwidth divided by the model file size. One published, unverified benchmark on a 4-vCPU Xeon VPS reports 3.2 to 4.5 tokens a second for 7–8B models at Q4_K_M. Fine for an internal summarizer, too slow for customer chat. Once you have a model (see below), benchmark your own VPS with -t set to its vCPU count:

docker run --rm -v /srv/models:/models:ro \
  ghcr.io/ggml-org/llama.cpp:full-b12648@sha256:17b7e23a19e3971267cc545f0f3f5e2c5d4cee1840967bddbc7694b4bd9996e4 \
  --bench -m /models/qwen3.5-4b-gguf/Qwen3.5-4B-Q4_K_M.gguf -t 4

Size the memory. Weights take about parameters × bytes per parameter: 2 at BF16, 1 at FP8, about 0.5–0.6 at 4-bit. Add the KV cache, which grows with context × concurrent requests, plus 10–20% overhead. Size mixture-of-experts models by total parameters.

ModelLicenseWeightsFits on
Qwen3.5-4BApache-2.0about 9 GB at BF16 (9.32 GB with the vision encoder), 3.0 GB as Q4_K_Ma CPU VPS or any 24 GB GPU
Qwen3.5-9BApache-2.0about 19 GB at BF16a 24 GB GPU, with a capped context
gpt-oss-20bApache-2.0MXFP4; its card says it can "run within 16GB of memory"a 24 GB GPU
Qwen3.8-27BApache-2.0about 31 GB at FP8a 96 GB GPU

Choose a model and check its license

Licenses apply per checkpoint, so read the license on the exact repository you download. As of 23 November 2026:

  • Apache-2.0: Qwen3.5 (0.8B to 9B), Qwen3.8-27B, Gemma 4, Ministral 3, gpt-oss (which needs the harmony chat format), Meta's Muse Glimmer 30B and IBM Granite 4.x. Ship the license and NOTICE file with any redistribution.
  • Same vendor, different terms: Qwen3.8-Flash-Next uses the custom qwen-community-1.0 license.
  • Llama 4 Community License: products with more than 700 million monthly active users at release need a separate license from Meta; you must display "Built with Llama"; distributed fine-tunes must have names starting with "Llama". For the multimodal models, which include Scout and Maverick, the Acceptable Use Policy withholds the license from "an individual domiciled in, or a company with a principal place of business in, the European Union", but this "does not apply to end users of a product or service that incorporates any such multimodal models."

The examples use Qwen3.5-9B on a GPU and the Qwen3.5-4B Q4_K_M build from ggml-org (the llama.cpp maintainers) on a CPU, both tagged Apache-2.0.

Set up the server

Firewall and SSH

Step 1 in the diagram. Allow SSH only from your own address, and HTTPS from anywhere:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow proto tcp from 203.0.113.10 to any port 22   # your workstation's IP
sudo ufw allow 443/tcp
sudo ufw enable

Docker routes traffic to published ports before ufw sees it, so ufw doesn't protect containers. The Compose file below protects the model by publishing only Caddy's port 443 and a Grafana port on 127.0.0.1.

Then turn off password and root logins. Create a non-root sudo user with your SSH key first, because this locks root out. sshd keeps the first value it reads, and Ubuntu includes /etc/ssh/sshd_config.d/*.conf first, so a 00-... file wins. Keep your session open until a new login works:

sudo tee /etc/ssh/sshd_config.d/00-hardening.conf > /dev/null <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
EOF
sudo sshd -t && sudo systemctl restart ssh.service
sudo sshd -T | grep -Ei 'passwordauthentication|kbdinteractiveauthentication|permitrootlogin'

Docker and the NVIDIA runtime

Install Docker Engine and the Compose plugin from Docker's apt repository. On a GPU server, install a driver with sudo ubuntu-drivers install --gpgpu plus the matching nvidia-utils-VERSION-server package (Ubuntu's guide), reboot, and check nvidia-smi. Then install the NVIDIA Container Toolkit at the version NVIDIA's guide lists and run NVIDIA's sample test, with its ubuntu image pinned:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
  sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
  sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.20.2-1
sudo apt-get install -y \
  nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
  libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
sudo docker run --rm --runtime=nvidia --gpus all \
  ubuntu:24.04@sha256:9c7f200c07e3d4a03e7249d2c16bf66a51120fb876aa2242cf31451412543289 nvidia-smi

Skip this on a CPU-only VPS.

Pin the weights

Step 4 in the diagram. Download once at a fixed commit and check each large file against the Hub's SHA-256. After that, nothing at runtime needs the internet.

sudo apt-get install -y python3-venv
python3 -m venv ~/hf && ~/hf/bin/pip install "huggingface_hub==2.4.0"
 
REPO=Qwen/Qwen3.5-9B
REV=$(curl -s "https://huggingface.co/api/models/$REPO" | python3 -c 'import json,sys; print(json.load(sys.stdin)["sha"])')
echo "$REPO@$REV"    # record this next to your compose file
 
sudo mkdir -p /srv/models && sudo chown "$USER" /srv/models
~/hf/bin/hf download "$REPO" --revision "$REV" --local-dir /srv/models/qwen3.5-9b

For the CPU model, set REPO=ggml-org/Qwen3.5-4B-GGUF, add Qwen3.5-4B-Q4_K_M.gguf after "$REPO", and use /srv/models/qwen3.5-4b-gguf. Save as verify_weights.py:

import hashlib, json, pathlib, sys, urllib.request
 
repo, rev, root = sys.argv[1], sys.argv[2], pathlib.Path(sys.argv[3])
url = f"https://huggingface.co/api/models/{repo}/tree/{rev}?recursive=true"
with urllib.request.urlopen(url) as resp:
    entries = [e for e in json.load(resp) if e.get("lfs")]
 
failed = 0
for e in entries:
    path = root / e["path"]
    if not path.exists():
        print("skip", e["path"])  # not downloaded, e.g. other quantizations
        continue
    digest = hashlib.sha256()
    with open(path, "rb") as fh:
        for chunk in iter(lambda: fh.read(1 << 20), b""):
            digest.update(chunk)
    ok = digest.hexdigest() == e["lfs"]["oid"]
    failed += not ok
    print("ok  " if ok else "BAD ", e["path"])
sys.exit(1 if failed else 0)

Run it, then write a local manifest and re-check it before every restart:

python3 verify_weights.py "$REPO" "$REV" /srv/models/qwen3.5-9b
cd /srv/models/qwen3.5-9b
find . -type f -not -path './.cache/*' -print0 | sort -z | xargs -0 sha256sum > ../qwen3.5-9b.sha256
sha256sum --quiet -c ../qwen3.5-9b.sha256 && echo "weights unchanged"

Write the Compose file

Steps 2, 3 and 5 in the diagram. The internal network has no route to the internet; only Caddy and Grafana also join edge. The model server is on internal alone, so nothing outside reaches it and it can't call out.

Generate a key with openssl rand -hex 32, put it in /srv/llm/.env, and chmod 600 that file:

LLM_DOMAIN=llm.example.com
LLM_API_KEY=paste-the-output-of-openssl-rand-hex-32
GRAFANA_ADMIN_PASSWORD=choose-a-long-password

Then /srv/llm/compose.yaml, with every image pinned by the digest current on 23 November 2026:

services:
  llm:
    image: vllm/vllm-openai:v0.34.0@sha256:20fdb089454afbb324efa4110a2c025ff7b27cc1a086e07aa580b18df8ad1ce1
    command:
      - --model=/models/qwen3.5-9b
      - --served-model-name=qwen3.5-9b
      - --max-model-len=32768
      - --language-model-only
      - --reasoning-parser=qwen3
    environment:
      VLLM_API_KEY: ${LLM_API_KEY:?missing}
      HF_HUB_OFFLINE: "1"
      VLLM_NO_USAGE_STATS: "1"
    volumes:
      - /srv/models:/models:ro
    shm_size: 8gb
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    networks: [internal]
    restart: unless-stopped
 
  caddy:
    image: caddy:2.11.9@sha256:4851e54a46b206517c574821bb5cc67f170d2156041e9fbc4c9193b45e84a75b
    ports:
      - "443:443"
    environment:
      LLM_DOMAIN: ${LLM_DOMAIN:?missing}
      LLM_API_KEY: ${LLM_API_KEY:?missing}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    networks: [edge, internal]
    restart: unless-stopped
 
  prometheus:
    image: prom/prometheus:v3.16.0@sha256:e04987641b57704f408e31f6373ba4138ecf27cb4a165d24aabb6c38fddd0f06
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus_data:/prometheus
    networks: [internal]
    restart: unless-stopped
 
  grafana:
    image: grafana/grafana:13.3.1@sha256:0615ec4fbd4072004b7d86b46ded63013a74b7d6eb1119273dd89e8fa25c13cf
    ports:
      - "127.0.0.1:3000:3000"
    environment:
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:?missing}
    volumes:
      - ./grafana-datasource.yml:/etc/grafana/provisioning/datasources/prometheus.yml:ro
      - grafana_data:/var/lib/grafana
    networks: [edge, internal]
    restart: unless-stopped
 
networks:
  edge: {}
  internal:
    internal: true
 
volumes:
  caddy_data: {}
  caddy_config: {}
  prometheus_data: {}
  grafana_data: {}

What the model settings do:

  • --max-model-len caps the context so the KV cache fits beside 19 GB of weights. --language-model-only skips the vision encoder, as the Qwen3.5 model card suggests for text-only use. --reasoning-parser puts the thinking Qwen3.5 does by default in its own field.
  • --gpu-memory-utilization is unset. Since v0.34 it defaults to 1.0, and the release notes advise leaving it unset unless another process shares the GPU.
  • VLLM_API_KEY is the environment form of --api-key. In v0.34.0 it guards only paths starting with /v1, /v2, /inference and /cohere. Everything else stays open: /invocations, /tokenize and /metrics always; /pooling, /classify, /score and /rerank with pooling models; /pause and /update_weights when VLLM_SERVER_DEV_MODE is set (route registration). Hence the internal network and Caddy forwarding only /v1/*.
  • HF_HUB_OFFLINE stops Hub lookups; VLLM_NO_USAGE_STATS opts out of usage statistics.

On a CPU-only VPS, replace the llm service with llama.cpp's server:

  llm:
    image: ghcr.io/ggml-org/llama.cpp:server-b12648@sha256:20db01dc9a92bff54a5b9fe4078caa52be6a0c1fa73859c6449e25b9cb67f998
    command: ["-m", "/models/qwen3.5-4b-gguf/Qwen3.5-4B-Q4_K_M.gguf", "--alias", "qwen3.5-4b",
              "-c", "8192", "--metrics", "--no-webui",
              "--chat-template-kwargs", '{"enable_thinking": false}']
    volumes:
      - /srv/models:/models:ro
    networks: [internal]
    restart: unless-stopped

Its image listens on port 8080, so use llm:8080 in the Caddyfile and prometheus.yml. Thinking is off because, at a few tokens a second, a long thinking trace takes minutes. A llama-server --api-key would also guard /metrics, so we leave the key check to Caddy.

Configure Caddy

Step 2 in the diagram. /srv/llm/Caddyfile:

{$LLM_DOMAIN} {
	tls {
		issuer acme {
			disable_http_challenge
		}
	}
 
	@authorized {
		path /v1/*
		header Authorization "Bearer {$LLM_API_KEY}"
	}
 
	handle @authorized {
		reverse_proxy llm:8000
	}
 
	handle {
		respond "Unauthorized" 401
	}
}

Caddy gets and renews a Let's Encrypt certificate itself. With port 80 closed only the TLS-ALPN challenge on port 443 can succeed, so the HTTP challenge is off. Only /v1/ paths with an exactly matching Authorization header reach the model; everything else gets a 401. {$LLM_DOMAIN} and {$LLM_API_KEY} come from Caddy's environment. Caddy writes no access logs unless you add a log directive, and then redacts the Authorization header by default.

One shared key is the minimum; for per-caller quotas and metering, add a gateway as the AWS guide describes.

Configure Prometheus and Grafana

Step 5 in the diagram. /srv/llm/prometheus.yml:

global:
  scrape_interval: 15s
scrape_configs:
  - job_name: llm
    static_configs:
      - targets: ["llm:8000"]

And /srv/llm/grafana-datasource.yml:

apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true

vLLM's /metrics exports vllm:e2e_request_latency_seconds, vllm:num_requests_waiting, vllm:kv_cache_usage_perc and more, and vLLM publishes an example Grafana dashboard. Start by alerting on p95 latency and a queue that stays above zero:

histogram_quantile(0.95, sum by (le) (rate(vllm:e2e_request_latency_seconds_bucket[5m])))
sum(vllm:num_requests_waiting)

For GPU memory and temperature, add NVIDIA's DCGM exporter. Reach Grafana through an SSH tunnel (ssh -L 3000:127.0.0.1:3000 you@your-server, then http://localhost:3000); its alerting can send to email or Slack.

Start it and run the smoke tests

cd /srv/llm
docker compose pull && docker compose up -d
docker compose logs -f llm     # wait for "Application startup complete"
docker compose logs caddy      # confirm the certificate was issued

Then, from your workstation:

export LLM_API_KEY=...   # the value from .env
 
# Without a key: expect 401
curl -s -o /dev/null -w "%{http_code}\n" https://llm.example.com/v1/models
 
# With the key: the model list
curl -s https://llm.example.com/v1/models -H "Authorization: Bearer $LLM_API_KEY"
 
# A chat completion, thinking off for a quick answer
curl -s https://llm.example.com/v1/chat/completions \
  -H "Authorization: Bearer $LLM_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "qwen3.5-9b", "messages": [{"role": "user", "content": "Reply with one word: ready"}], "max_tokens": 20, "chat_template_kwargs": {"enable_thinking": false}}'
 
# The model port must not answer from outside
curl -s --max-time 5 http://SERVER_IP:8000/v1/models || echo "not reachable, as intended"

Existing code needs only a new base URL. After pip install "openai==3.57.0":

import os
from openai import OpenAI
 
client = OpenAI(base_url="https://llm.example.com/v1", api_key=os.environ["LLM_API_KEY"])
resp = client.chat.completions.create(
    model="qwen3.5-9b",
    messages=[{"role": "user", "content": "Name three uses for a private LLM."}],
    max_tokens=300,
    extra_body={"chat_template_kwargs": {"enable_thinking": False}},
)
print(resp.choices[0].message.content)

Harden it

  • Pin image digests and package versions; never deploy latest. On 21 October 2026, LiteLLM's latest, main-latest and main-stable tags served credential-stealing malware for up to about two and a half hours, with a valid signature from LiteLLM's old key. Pin digests you have checked (docker buildx imagetools inspect IMAGE:TAG prints them).
  • Treat model files as code. Two 2026 vLLM CVEs let a malicious model repository run code even with trust_remote_code off: CVE-2026-27893 (fixed in v0.18.0) and CVE-2026-90553 (fixed in v0.28.0). Run a current release, load only safetensors from vetted repositories at a pinned revision, and keep --trust-remote-code off (the default).
  • Never publish the model port, and keep its egress closed. vLLM's key check doesn't cover every path, Docker bypasses ufw, and with no route out, anything malicious in the container has nowhere to send what it finds.
  • SSH keys only, set up above.
  • No prompt logging by default. vLLM logs requests only with --enable-log-requests, and prompt text only at DEBUG level. If you log prompts, decide who reads them and when they are deleted.
  • Rotate the key by editing .env and running docker compose up -d.

Upgrade and roll back

Keep /srv/llm in git, with .env in .gitignore.

  1. Read the release notes. vLLM v0.34's "Before you upgrade" table lists breaking changes, such as a KV cache block size of 64 instead of 16.
  2. Get the new digest with docker buildx imagetools inspect vllm/vllm-openai:NEW_TAG, update the image line and commit.
  3. Run docker compose pull llm && docker compose up -d llm, repeat the smoke tests and watch Grafana.
  4. To roll back, revert the commit and run docker compose up -d llm; the old image stays on disk until you prune it.
  5. For a new model, download it to a new directory, point --model at it and keep --served-model-name. Keep the old directory until the new model has proven itself.

On one server, every upgrade means downtime while the model reloads.

When to move to AWS or Google Cloud

Move when one server's downtime is unacceptable, when traffic needs autoscaling, when data must stay in a country without your provider's GPUs (Hetzner's are in Finland and Germany), when teams need their own keys and quotas, or when auditors expect IAM roles, KMS keys and cloud audit trails. See the AWS and Google Cloud guides, or the self-host vs API guide.

Sources

Fit check

Should you run your own model? Let's find out.

Sixty minutes on your workload, volumes and data rules. You leave with a recommendation, even when the answer is to stay on an API.