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.
This commit is contained in:
+12
-3
@@ -1,15 +1,24 @@
|
|||||||
services:
|
services:
|
||||||
chroma:
|
chroma:
|
||||||
image: chromadb/chroma:latest
|
image: chromadb/chroma:latest
|
||||||
ports:
|
expose:
|
||||||
- '8666:8000'
|
- '8000'
|
||||||
environment:
|
environment:
|
||||||
- CHROMA_SERVER_HOST=0.0.0.0
|
- CHROMA_SERVER_HOST=0.0.0.0
|
||||||
- CHROMA_SERVER_HTTP_PORT=8000
|
- CHROMA_SERVER_HTTP_PORT=8000
|
||||||
- CHROMA_SERVER_CORS_ALLOW_ORIGINS=["*"]
|
|
||||||
volumes:
|
volumes:
|
||||||
- chroma_data:/chroma/chroma
|
- chroma_data:/chroma/chroma
|
||||||
restart: unless-stopped
|
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:
|
volumes:
|
||||||
chroma_data:
|
chroma_data:
|
||||||
|
|||||||
+41
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user