~/tools / Run a local LLM on your server / Ollama nginx Config Generator

Ollama nginx Config Generator — Build an nginx config for Ollama: HTTPS, basic auth, allow list, streaming

Build an nginx server block that puts Ollama behind a proxy: HTTPS with your certificate, a redirect from port 80, a password with basic authentication, an address allow list, and settings that let streamed answers arrive as they are written. It starts from the proxy example in the official Ollama FAQ and uses only directives from the nginx documentation. Nothing leaves your browser.

Server
Who can reach it

With a password and an allow list, a request has to pass both (nginx's satisfy defaults to all).

Streaming and limits

nginx configuration

Save it as /etc/nginx/conf.d/ollama.conf. The combination of directives is ours, so always run nginx -t before you reload.

server {
    listen 80;
    server_name ollama.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name ollama.example.com;

    ssl_certificate /etc/ssl/ollama.crt;
    ssl_certificate_key /etc/ssl/ollama.key;

    auth_basic "ollama";
    auth_basic_user_file /etc/nginx/ollama.htpasswd;

    location / {
        proxy_pass http://localhost:11434;
        proxy_set_header Host localhost:11434;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_read_timeout 300s;
    }
}

Commands

htpasswd asks for the password. Its -c option creates a new file, and an existing file is rewritten, so leave it out when you add a second user. On Ubuntu, htpasswd is in the apache2-utils package.

sudo htpasswd -c /etc/nginx/ollama.htpasswd alice
sudo nginx -t
sudo nginx -s reload

Directives and defaults as given in the nginx documentation and the proxy example in the Ollama FAQ, checked on 2026-11-03. Ollama FAQ: proxy server / nginx: ngx_http_proxy_module

Everything is done in your browser. Nothing you enter is sent anywhere.

Ollama listens only on the server itself by default, and the Ollama FAQ describes no authentication for it. When another machine has to reach it, the FAQ points to a proxy server such as nginx, with an example that forwards requests to http://localhost:11434 and sets the Host header to localhost:11434. This tool builds on that example with directives from the nginx documentation: listen 443 ssl with a certificate and key, a server on port 80 that redirects to HTTPS, auth_basic with a password file, allow and deny for addresses, client_max_body_size, proxy_http_version 1.1, proxy_buffering off for streaming, and proxy_read_timeout for a slow first answer. The combination is ours, not a single example from the documents, so we tested it: the output passed nginx -t on the official nginx 1.29.8 image and on nginx 1.24.0 from Ubuntu 24.04, and through nginx 1.29.8 we reached Ollama 0.40.11 only with the right password, saw a streamed answer arrive in 81 pieces, and got 403 from an address outside the allow list.

The core logic of this tool is open source under the MIT License. github.com/seigo5555/toolkitbox-lib/src/ollama-nginx.ts

Use Cases

  • Reach Ollama on a VPS from your laptop or another server, with a password and HTTPS
  • Let only your office or home address reach Ollama, on top of the password
  • Fix answers that arrive all at once, or connections that close while a large model is still loading

Usage

  1. Enter the domain name and, if Ollama is not on the same server at port 11434, the address nginx should forward to. Turn on HTTPS and enter the paths of your certificate and private key.
  2. Choose how to limit access: a password, a list of allowed addresses, or both. With both, a request must pass both, because nginx's satisfy directive defaults to all. Keep streaming on, and raise the timeout if your model takes long to load.
  3. Save the configuration as /etc/nginx/conf.d/ollama.conf, create the password file with the htpasswd command shown, then run nginx -t and reload nginx.

FAQ

Why is the Host header always localhost:11434?

That is what the Ollama FAQ's example sets. Ollama refuses requests whose Host header names a host it does not know: when we tested Ollama 0.40.11, Host: ollama.example.com got 403 while localhost:11434 and even localhost:9999 got 200. Sending localhost:11434 keeps the request accepted whatever name the visitor used.

Why turn proxy_buffering off?

Ollama streams an answer piece by piece. The nginx documentation says that when buffering is disabled, the response is passed to the client synchronously, immediately as it is received; when it is enabled, nginx saves the response into buffers first. With it off, our test answer arrived in 81 pieces over about six seconds.

What does proxy_read_timeout change?

The nginx documentation says the timeout, 60 seconds by default, is set only between two successive reads, not for the whole response, and that the connection is closed if the proxied server sends nothing within it. Our reading, not a statement from the documents: a model that is still being loaded into memory can stay silent for longer than a minute on a small server, so a higher value avoids a closed connection.

Which file does nginx read?

Both the official nginx image and Ubuntu 24.04's nginx package include /etc/nginx/conf.d/*.conf inside the http block of nginx.conf, so a file saved there is read. Other installations may use a different directory; check the include lines in your nginx.conf.

How do I create the password file?

The nginx documentation names the htpasswd utility from Apache and openssl passwd, without giving commands. The tool shows htpasswd -c with the file and user name you entered. On Ubuntu, htpasswd comes in the apache2-utils package. The Apache documentation says that -c creates the file and that an existing file is rewritten and truncated, so leave -c out when you add a second user.

Is anything sent to a server?

No. The configuration is put together in your browser.

Related articles

Related