From b62ad15be84197fd62a412fc500fce7886de3fa1 Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Tue, 19 May 2026 22:15:04 +0200 Subject: [PATCH] fix: move CORS OPTIONS handling into nginx location block Nginx does not allow add_header inside if blocks at the server level. Moving the OPTIONS preflight response into the location / block fixes the emerg directive error and allows nginx to start correctly. --- nginx.conf | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/nginx.conf b/nginx.conf index 5765198..096df26 100644 --- a/nginx.conf +++ b/nginx.conf @@ -7,24 +7,21 @@ http { listen 8666; server_name localhost; - # CORS: allow any origin, including app://obsidian.md + # Global CORS headers for all responses 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 / { + # Handle preflight OPTIONS + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + proxy_pass http://chroma:8000; proxy_http_version 1.1; proxy_set_header Host $host;