SaonBD | Paragraph logo

Subscribe to SaonBD | Paragraph

Get new posts delivered straight to your inbox.

All posts

Reverse Proxying Local LLMs on Linux with Caddy and TLS

A practical guide to securing local Ollama and Open WebUI setups on Linux using Caddy reverse proxy and automatic TLS encryption.

Reverse Proxying Local LLMs on Linux with Caddy and TLS

Reverse Proxying Local LLMs on Linux with Caddy and TLS

Running local AI models with Ollama and Open WebUI gives you complete data privacy. Accessing your WebUI interface over unencrypted HTTP or raw IP addresses creates network exposure and browser warnings. A reverse proxy solves this problem by routing traffic through a clean domain name with automatic HTTPS encryption.

Caddy is a lightweight reverse proxy for home labs and self-hosted Linux servers. It handles TLS certificate generation automatically using Let's Encrypt or internal zero-trust certificates, requires minimal configuration, and runs cleanly alongside Docker containers.

Prerequisites

Make sure that you have these components configured before starting:

  • A Linux server running Ubuntu, Debian, or RHEL.

  • Docker and Docker Compose installed on your system.

  • Ollama and Open WebUI running on local ports.

  • A domain name pointing to your server IP address, or a local DNS entry.

Step 1: Install Caddy on Linux

Install Caddy directly on your host operating system using the official package repository:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

Step 2: Update Docker Compose Network Binding

Open WebUI binds to port 8080 across all interfaces by default. Bind Open WebUI to loopback (127.0.0.1) in your docker-compose.yml file to ensure traffic passes only through your reverse proxy:

version: '3.8'

services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    restart: always
    ports:
      - "127.0.0.1:8080:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
    volumes:
      - open-webui:/app/backend/data

volumes:
  open-webui:

Apply the configuration change by restarting the container stack:

docker compose up -d

Step 3: Configure the Caddyfile

Open /etc/caddy/Caddyfile in your text editor:

sudo nano /etc/caddy/Caddyfile

Add the following reverse proxy block. Replace ai.example.com with your actual domain or hostname:

ai.example.com {
    reverse_proxy 127.0.0.1:8080
}

Add a second block if you want to proxy direct Ollama API calls on a separate subdomain:

ai.example.com {
    reverse_proxy 127.0.0.1:8080
}

ollama.example.com {
    reverse_proxy 127.0.0.1:11434
}

Step 4: Reload Caddy and Verify TLS

Validate your Caddyfile configuration and reload the service daemon:

sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy

Caddy automatically fetches a valid TLS certificate from Let's Encrypt for public domain names. For internal network hostnames, Caddy provisions local HTTPS certificates automatically.

Step 5: Test Connection and Security

Verify that your local AI interface responds correctly over HTTPS:

curl -I https://ai.example.com

You can now access Open WebUI over an encrypted HTTPS connection without exposing raw application ports.

Related guides

Join the discussion

Have a thought or a correction? Send it over — your message opens in your email app.

Subscribe

Get new posts delivered to your inbox.