New Tool Radar

Local AI

How to Put a Password on Ollama with Nginx

Keep Ollama listening on localhost and put nginx in front of it with basic authentication, so anyone who reaches it has to log in first.

Schematic diagram with three steps: keep Ollama on localhost, add a password with nginx auth_basic, then check that a request without a login is refused.

Out of the box, Ollama answers anyone who can reach its port without asking who they are. Ollama binds 127.0.0.1 port 11434 by default, and its API documentation states plainly that the local API at port 11434 does not require authentication: anyone who can reach the port can run prompts, list models, pull new ones, and delete existing ones. Ollama has no user accounts, so authentication has to live in front of it. Nginx is the common choice, and the setup is: leave Ollama on localhost, put a reverse proxy on the same box, and let only the proxy face the network.

The nginx block

Ollama’s FAQ says the server runs an HTTP server and can be exposed using a proxy server such as Nginx, configured to forward requests. A business-deployment guide gives the block with the password lines added:

location / { auth_basic "Ollama"; auth_basic_user_file /etc/nginx/ollama.htpasswd; proxy_pass http://localhost:11434; proxy_set_header Host localhost:11434; proxy_buffering off; proxy_read_timeout 600s; }

Line What it does
auth_basic "Ollama"; Asks every visitor for a username and password; “Ollama” is the name shown in the login prompt
auth_basic_user_file /etc/nginx/ollama.htpasswd; Points at the password file, which holds one name:hashed-password line per user, created with the htpasswd utility
proxy_pass http://localhost:11434; Forwards the request to Ollama on localhost
proxy_set_header Host localhost:11434; Sets the Host header Ollama expects
proxy_buffering off; Stops nginx buffering the streamed answer; Ollama streams tokens as they are generated, and buffering can hold them back so the user stares at a blank box and then gets the whole answer at once
proxy_read_timeout 600s; Raises the wait for the next read from 60 seconds, the nginx default; a cold model load followed by a long document can exceed 60 seconds before the first token arrives

The two lines at the end exist because of how language models answer, not because of Ollama’s settings. Leave Ollama itself on its default bind address; do not set OLLAMA_HOST=0.0.0.0 to expose it, because that binds every interface and leaves the unauthenticated port open to the network.

Try it: check the login prompt

With nginx running in front of Ollama, open the address in a browser or send a request without credentials, and check the three results.

Check What you should see What it means
No credentials The browser asks for a username and password The proxy is asking who is calling before Ollama sees anything
Right login Ollama answers as usual The proxy forwarded the request after the login
Ollama itself Still listening only on 127.0.0.1:11434 Only the proxy faces the network, not Ollama directly

Expected result. We checked Ollama’s FAQ, which describes exposing Ollama with a proxy server such as Nginx, and the business-deployment guide, which gives the nginx block with the password lines. We did not set up nginx or Ollama behind a proxy on this machine, so the login prompt above is the expected result, not a tested one.

Limits

Basic authentication sends credentials with every request, so serve this over HTTPS; the guide’s own advice is to do exactly that. Ollama’s own FAQ proxy example has no TLS and no authentication — the password lines are the addition, and they come from the third-party guide, not from Ollama’s documentation. This does not give Ollama user accounts: anyone with the shared password gets full API access, including pulling and deleting models, so consider blocking the pull and delete endpoints at the proxy for everyone except an administrator. The password file holds hashed passwords, but it is still a file to protect like any other credential store. We did not test any of this ourselves.

Sources

See all