A browser normally prevents a web app from reading an API response from a different origin, even when both run on one computer. For an Ollama systemd service on Linux, allowed origins let a trusted frontend read responses from the local API.

Ollama reads its origin settings when the server starts. A service drop-in makes the setting persist across restarts; exporting a variable in a terminal does not change the already-running service. An installed ollama service, sudo access, and curl are required.

The API must already be reachable from the computer running the browser. CORS controls browser access to responses, but provides neither authentication nor a firewall, and changing allowed origins does not change the API's listening address.

Allowing every origin with * lets untrusted websites access a reachable Ollama API from a visitor's browser. An explicit trusted origin limits that exposure. Restarting Ollama interrupts active requests.

Steps to set allowed origins in Ollama:

  1. Inspect the Ollama service and its existing drop-ins.
    $ sudo systemctl cat ollama

    The service should start ollama serve. Existing drop-ins appear after the main unit. The dedicated origins.conf below must be new; replacing an existing file would discard its contents. An existing OLLAMA_ORIGINS assignment needs updating in its owning file, with a saved copy for recovery, rather than a conflicting second definition.

  2. Add the trusted frontend origin in a dedicated service drop-in.
    $ sudo systemctl edit --drop-in=origins.conf --stdin ollama <<'EOF'
    [Service]
    Environment="OLLAMA_ORIGINS=https://app.example.net"
    EOF

    This requires systemd 256 or newer and writes a dedicated origins.conf drop-in, replacing that file if it exists. The edit also reloads systemd's unit configuration. An origin includes the scheme, hostname, and port when non-default, without a path or trailing slash. The value must match the frontend's origin; multiple additional origins use a comma-separated list without spaces.

    If the newly added drop-in must be removed, the rollback is:

    $ sudo rm /etc/systemd/system/ollama.service.d/origins.conf
    $ sudo systemctl daemon-reload
    $ sudo systemctl restart ollama

    For a previously existing file, restoring its saved contents before the reload preserves the earlier settings.

  3. Restart Ollama to apply the origin setting.
    $ sudo systemctl restart ollama
  4. Confirm the local API answers after the restart.
    $ curl -fsS --retry 5 --retry-connrefused --retry-delay 1 http://127.0.0.1:11434/api/version
    {"version":"0.40.12"}

    The retry options allow for the listener starting after systemd reports the service active. The version depends on the installed release.

  5. Check that the trusted origin passes a JSON request preflight.
    $ curl -si -X OPTIONS \
      -H 'Origin: https://app.example.net' \
      -H 'Access-Control-Request-Method: POST' \
      -H 'Access-Control-Request-Headers: Content-Type' \
      http://127.0.0.1:11434/api/chat
    HTTP/1.1 204 No Content
    ##### snipped #####
    Access-Control-Allow-Methods: GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS
    Access-Control-Allow-Origin: https://app.example.net
    ##### snipped #####

    The response must allow the requesting origin, the POST method, and the Content-Type header. Preflight checks permission before a browser sends a cross-origin JSON request; it does not run a model.

  6. Verify an API response includes the trusted origin.
    $ curl -si -H 'Origin: https://app.example.net' \
      http://127.0.0.1:11434/api/version
    HTTP/1.1 200 OK
    Access-Control-Allow-Origin: https://app.example.net
    Content-Type: application/json; charset=utf-8
    Vary: Origin
    ##### snipped #####
     
    {"version":"0.40.12"}

    The response names the origin rather than returning a wildcard. Curl displays the server's CORS policy without enforcing browser restrictions; browsers may also apply mixed-content or local-network permissions.

  7. Confirm Ollama still permits its built-in localhost origins.
    $ curl -si -H 'Origin: http://localhost:3000' \
      http://127.0.0.1:11434/api/version
    HTTP/1.1 200 OK
    Access-Control-Allow-Origin: http://localhost:3000
    ##### snipped #####

    Additional origins do not replace the built-in defaults. Ollama retains HTTP and HTTPS origins for localhost, 127.0.0.1, and 0.0.0.0, including arbitrary ports, along with its built-in app, file, Tauri, and VS Code origin patterns.

  8. Verify an unlisted web origin receives no CORS permission.
    $ curl -si -H 'Origin: https://denied.example.net' \
      http://127.0.0.1:11434/api/version
    HTTP/1.1 403 Forbidden
    ##### snipped #####

    An unlisted origin receives HTTP 403 without an Access-Control-Allow-Origin header. Clients that omit or change the Origin header can still call the reachable API, so the allowlist does not restrict network clients.

Share this guide