Caddyfile.localhost 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Run with
  2. # caddy run --envfile ./example.env --config ./Caddyfile.localhost
  3. #
  4. # This is configured for
  5. # - Automatic HTTPS (even for localhost)
  6. # - Reverse Proxying to Ollama API Base URL (http://localhost:11434/api)
  7. # - CORS
  8. # - HTTP Basic Auth API Tokens (uncomment basicauth section)
  9. # CORS Preflight (OPTIONS) + Request (GET, POST, PATCH, PUT, DELETE)
  10. (cors-api) {
  11. @match-cors-api-preflight method OPTIONS
  12. handle @match-cors-api-preflight {
  13. header {
  14. Access-Control-Allow-Origin "{http.request.header.origin}"
  15. Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
  16. Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
  17. Access-Control-Allow-Credentials "true"
  18. Access-Control-Max-Age "3600"
  19. defer
  20. }
  21. respond "" 204
  22. }
  23. @match-cors-api-request {
  24. not {
  25. header Origin "{http.request.scheme}://{http.request.host}"
  26. }
  27. header Origin "{http.request.header.origin}"
  28. }
  29. handle @match-cors-api-request {
  30. header {
  31. Access-Control-Allow-Origin "{http.request.header.origin}"
  32. Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
  33. Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
  34. Access-Control-Allow-Credentials "true"
  35. Access-Control-Max-Age "3600"
  36. defer
  37. }
  38. }
  39. }
  40. # replace localhost with example.com or whatever
  41. localhost {
  42. ## HTTP Basic Auth
  43. ## (uncomment to enable)
  44. # basicauth {
  45. # # see .example.env for how to generate tokens
  46. # {env.OLLAMA_API_ID} {env.OLLAMA_API_TOKEN_DIGEST}
  47. # }
  48. handle /api/* {
  49. # Comment to disable CORS
  50. import cors-api
  51. reverse_proxy localhost:11434
  52. }
  53. # Same-Origin Static Web Server
  54. file_server {
  55. root ./build/
  56. }
  57. }