[GH-ISSUE #903] Add HTTP Basic Auth #437

Closed
opened 2026-04-12 10:05:39 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @jaideep2 on GitHub (Oct 25, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/903

Implement this

Here's how you add HTTP Basic Auth with caddy as a reverse proxy to localhost:11434, and also handle HTTPS automatically:

  1. Install caddy
    # Mac, Linux
    curl https://webi.sh/caddy | sh
    
    # Windows
    curl.exe https://webi.ms/caddy | powershell
    
  2. Put your password (which could be an API Token) in a password.txt
  3. Digest the password
    caddy hash-password < ./password.txt
    
  4. Put the username and digest in an ENV file
    caddy.env:
    BASIC_AUTH_USER='apitoken'
    BASIC_USER_AUTH='$2a$14$sI1j0RbhzKHMZ4cHU8otHOkB3Dgl9egF2D.CXB6C0/Qk5dtaMHS/u'
    
  5. Create a Caddyfile with basic auth using the ENVs
    api.example.com {
        handle /* {
            basicauth {
                {env.BASIC_AUTH_USERNAME} {env.BASIC_AUTH_DIGEST}
            }
            reverse_proxy localhost:11434
        }
    }
    
  6. Run caddy
    caddy run --config ./Caddyfile --envfile ./caddy.env
    

And if you want to run it as a system service, or without HTTPS or need other details, I've got a bunch of snippets up at https://webinstall.dev/caddy.

Originally posted by @coolaj86 in https://github.com/jmorganca/ollama/issues/849#issuecomment-1773697189

Originally created by @jaideep2 on GitHub (Oct 25, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/903 Implement this > Here's how you add HTTP Basic Auth with `caddy` as a reverse proxy to `localhost:11434`, and also handle HTTPS automatically: > > 0. Install caddy > ```sh > # Mac, Linux > curl https://webi.sh/caddy | sh > > # Windows > curl.exe https://webi.ms/caddy | powershell > ``` > 1. Put your password (which could be an API Token) in a `password.txt` > 2. Digest the password > ```sh > caddy hash-password < ./password.txt > ``` > 3. Put the username and digest in an ENV file \ > `caddy.env`: > ``` > BASIC_AUTH_USER='apitoken' > BASIC_USER_AUTH='$2a$14$sI1j0RbhzKHMZ4cHU8otHOkB3Dgl9egF2D.CXB6C0/Qk5dtaMHS/u' > ``` > 4. Create a `Caddyfile` with basic auth using the ENVs > ```Caddyfile > api.example.com { > handle /* { > basicauth { > {env.BASIC_AUTH_USERNAME} {env.BASIC_AUTH_DIGEST} > } > reverse_proxy localhost:11434 > } > } > ``` > 5. Run caddy > ```sh > caddy run --config ./Caddyfile --envfile ./caddy.env > ``` > > And if you want to run it as a system service, or _without_ HTTPS or need other details, I've got a bunch of snippets up at <https://webinstall.dev/caddy>. > _Originally posted by @coolaj86 in https://github.com/jmorganca/ollama/issues/849#issuecomment-1773697189_
Author
Owner

@jaideep2 commented on GitHub (Oct 25, 2023):

Sorry wrong repo

<!-- gh-comment-id:1778626188 --> @jaideep2 commented on GitHub (Oct 25, 2023): Sorry wrong repo
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#437