1. Reserve a domain
Navigate to the Domains section of the ngrok dashboard and click New + to reserve a free static domain likehttps://your-service.ngrok.app
or a custom domain you already own.
We’ll refer to this domain as $NGROK_DOMAIN
from here on out.
2. Create a Traffic Policy file
On the system where Ollama runs, create a file namedollama.yaml
and paste in the following policy:
Host
header of every HTTP request to localhost
so that Ollama accepts the requests.
3. Start your Ollama endpoint
On the same system where Ollama runs, start the agent on port11434
, which is the default for Ollama, and reference the ollama.yaml
file you just created.
Be sure to also change $NGROK_URL
to the domain you reserved earlier.
4. Try out your Ollama endpoint
You can usecurl
in your terminal to send a prompt to your LLM through your $NGROK_DOMAIN
, replacing $MODEL
with the Ollama model you pulled.
Optional: Protect your Ollama instance with Basic Auth
You may not want everyone to be able to access your LLM. ngrok can quickly add authentication to your LLM without any changes to your Ollama configuration. Edit yourollama.yaml
file and add in the policy below.
Authorization: Basic
header and a base64-encoded version of one of the username:password
pairs you specified in ollama.yaml
.
Only requests with valid Basic Auth are passed through to your ngrok agent and forwarded to your Ollama API.
Restart your ngrok agent to apply the new policy.
Authorization: Basic
header, once again replacing $NGROK_DOMAIN
and $MODEL
.
401 Unauthorized
response.
Your personal LLM is now locked down to only accept authenticated users.
What’s next?
- Read more about Traffic Policy, core concepts, and actions you might want to implement next, like IP restrictions instead of Basic Auth.
- Explore other ways to block unwanted requests from Tor users, search or AI bots, and more to protect your self-hosted LLM.
- View your Ollama traffic in Traffic Inspector.