Last active
January 31, 2025 00:31
-
-
Save drnic/afc4b630be53a6bb86f2747c8a06db64 to your computer and use it in GitHub Desktop.
We have a dedicated PC running ollama, with ngrok + static domain + basic auth. Problem: ollama cli doesn't yet pass basic auth via $OLLAMA_HOST Solution: this wrapper script which runs a tmp caddy server. Replace the url, username, pass for your ngrok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to handle cleanup on script exit | |
cleanup() { | |
echo "Cleaning up..." | |
kill -TERM "$caddy_pid" 2>/dev/null | |
rm -f "$caddy_config" | |
} | |
# Set up trap to call cleanup on EXIT, INT (Ctrl+C), and TERM signals | |
trap cleanup EXIT INT TERM | |
# Create a temporary Caddy configuration file | |
caddy_config=$(mktemp /tmp/Caddyfile.XXXXXX) | |
# Write the Caddy configuration to the temporary file | |
cat <<EOF > "$caddy_config" | |
:8080 | |
basicauth / { | |
username-here $(caddy hash-password -plaintext password-here) | |
} | |
reverse_proxy http://static-domain-on-ngrok.ngrok-free.app | |
EOF | |
# Start the Caddy proxy with the temporary configuration in the background | |
caddy run --config "$caddy_config" & | |
caddy_pid=$! | |
# Ensure Caddy has time to start (adjust if necessary) | |
sleep 2 | |
# Set the OLLAMA_HOST environment variable to point to the local proxy | |
export OLLAMA_HOST="http://localhost:8080" | |
# Run the ollama command | |
ollama "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment