New Tool Radar

Local AI

How to Serve a Local Ollama Model Behind Caddy with Automatic HTTPS

Put Caddy in front of your local Ollama server so it answers over HTTPS with a certificate Caddy obtains and renews itself.

Schematic diagram with three steps: the internet reaches Caddy over HTTPS on port 443, Caddy reverse-proxies to 127.0.0.1:11434, and Ollama stays bound to localhost.

Ollama binds 127.0.0.1 port 11434 by default, and its FAQ says it runs an HTTP server and can be exposed using a proxy server. Caddy is the proxy for readers who want HTTPS without managing certificates: Caddy will serve your proxy over HTTPS automatically and by default if it knows the hostname. The whole setup is one site block in a file called Caddyfile, and there is no certificate file to create, no renewal script to write, and no separate certificate tool to install.

The Caddyfile for Ollama

Caddy’s own reverse proxy quick-start shows the pattern with a placeholder backend. A Caddyfile with a site address and a reverse_proxy line is a working proxy, and changing the first line to your domain name turns on automatic HTTPS:

ollama.example.com {
    reverse_proxy 127.0.0.1:11434
}

Replace ollama.example.com with your own domain. The quick-start’s equivalent example is example.com with reverse_proxy :9000; here the backend is Ollama on 127.0.0.1:11434, so Ollama itself stays bound to localhost and only Caddy faces the network. Start Caddy from the directory holding the file with caddy run, and reload it with caddy reload if you change the Caddyfile. For a quick test without a file, the same proxy can be started from the command line as caddy reverse-proxy --from ollama.example.com --to 127.0.0.1:11434.

How the certificate works

If you use any domain name other than localhost, Caddy will attempt to get a publicly-trusted certificate; make sure your DNS records point to your machine and that ports 80 and 443 are open to the public and directed toward Caddy. If you use localhost or any domain ending in .localhost, Caddy will use an auto-renewing self-signed certificate instead, and the first time you do this you may need to enter a password as Caddy attempts to install its CA root certificate into your trust store. If you do not specify a port, Caddy defaults to 443 for HTTPS, and you need permission to bind to low ports — run as root, or run sudo setcap cap_net_bind_service=+p $(which caddy) to give Caddy that capability.

Try it: three checks from file to HTTPS reply

Check What you should see What it means
DNS and ports Your domain points at the machine, and ports 80 and 443 reach Caddy Caddy can obtain a publicly-trusted certificate
Caddy runs caddy run starts with your Caddyfile, and Ollama still listens on 127.0.0.1:11434 The proxy is in front of Ollama
HTTPS reply curl -v https://ollama.example.com/api/tags answers over HTTPS with your model list Ollama is served behind Caddy with automatic HTTPS

Expected result. We checked Caddy’s reverse proxy quick-start, which gives the Caddyfile pattern, the reverse-proxy command, the automatic HTTPS rules, and the low-port permission note, and Ollama’s FAQ, which gives the 127.0.0.1:11434 bind address and the proxy-server option. We did not install Caddy, write a Caddyfile, or serve Ollama behind a proxy on this machine.

Limits

This setup adds HTTPS only, not a login: the minimal Caddyfile above has no authentication, so anyone who can reach your domain can use the Ollama API, including listing, pulling, and deleting models. That is different from the nginx setup that adds a password prompt in front of Ollama; if you need access control, add authentication at the Caddy layer or keep the address private. A publicly-trusted certificate needs a real domain, public DNS pointing at the machine, and ports 80 and 443 reachable — without those, Caddy can only serve localhost with a self-signed certificate. Do not set OLLAMA_HOST=0.0.0.0 to expose Ollama directly; the point of the proxy is that Ollama stays on localhost. We did not test any of this ourselves.

Sources

See all