diff --git a/docker-compose.yml b/docker-compose.yml index e8bc6bc..4782fc4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,24 @@ services: chroma: image: chromadb/chroma:latest - ports: - - '8666:8000' + expose: + - '8000' environment: - CHROMA_SERVER_HOST=0.0.0.0 - CHROMA_SERVER_HTTP_PORT=8000 - - CHROMA_SERVER_CORS_ALLOW_ORIGINS=["*"] volumes: - chroma_data:/chroma/chroma restart: unless-stopped + nginx: + image: nginx:alpine + ports: + - '8666:8666' + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + - chroma + restart: unless-stopped + volumes: chroma_data: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..5765198 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,41 @@ +events { + worker_connections 1024; +} + +http { + server { + listen 8666; + server_name localhost; + + # CORS: allow any origin, including app://obsidian.md + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + + # Handle preflight OPTIONS + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + + location / { + proxy_pass http://chroma:8000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Support streaming + proxy_buffering off; + proxy_cache off; + proxy_read_timeout 86400s; + } + } +}