From 76887ea8ca18f8253e23e1032d046ff4d4239c1a Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Tue, 19 May 2026 22:08:11 +0200 Subject: [PATCH] feat: add Nginx reverse proxy for robust CORS handling Replace direct host port mapping with an Nginx reverse proxy that properly handles CORS for any origin, including Obsidian's app://obsidian.md. - docker-compose.yml: Add nginx service on port 8666, route to internal chroma:8000. Remove CORS env var from ChromaDB (handled by proxy now). - nginx.conf (new): Minimal alpine config with permissive CORS headers, preflight OPTIONS handling, and streaming support (proxy_buffering off). This fixes cross-origin access from remote Obsidian clients connecting over Tailscale or VPN. --- docker-compose.yml | 15 ++++++++++++--- nginx.conf | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 nginx.conf 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; + } + } +}