From 25def576e915be3b4421f531ca488a8b799b2476 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Wed, 3 Sep 2025 16:01:52 -0300 Subject: [PATCH] Fix 1600 --- proxy/nginx.conf | 60 ++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/proxy/nginx.conf b/proxy/nginx.conf index ce764e3..1887cc0 100644 --- a/proxy/nginx.conf +++ b/proxy/nginx.conf @@ -26,46 +26,40 @@ upstream frontend_admin { # --- Servidor para el Frontend Público / Widgets (Puerto 80) --- server { listen 80; - server_name elecciones2025.eldia.com; + server_name _; # Escucha en cualquier hostname - # --- INICIO: MANEJO GLOBAL Y ROBUSTO DE CORS --- - - # Para CUALQUIER petición OPTIONS (preflight), la interceptamos aquí mismo. - if ($request_method = 'OPTIONS') { - # Añadimos las cabeceras que el navegador espera en una respuesta preflight. - add_header 'Access-Control-Allow-Origin' $cors_origin always; - add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always; - add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; - # Le decimos al navegador que puede cachear esta respuesta preflight por 24 horas. - add_header 'Access-Control-Max-Age' 1728000; - add_header 'Content-Type' 'text/plain; charset=utf-8'; - # Respondemos con 204 (No Content) y terminamos la petición. - # NUNCA se pasará al servicio de frontend. - return 204; - } - - # Para todas las peticiones que NO son OPTIONS (como GET), añadimos - # la cabecera de origen para que el navegador las acepte. - add_header 'Access-Control-Allow-Origin' $cors_origin always; - add_header 'Access-Control-Allow-Credentials' 'true' always; - - # --- FIN: MANEJO GLOBAL DE CORS --- - - - # --- El resto de las rutas no cambian --- + # --- Ubicación para la API --- + # No necesita cabeceras CORS aquí, porque la API de .NET ya las gestiona. location /api/ { - proxy_pass http://backend_api; - 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_pass http://mercados-api:8080; + 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; # <-- Esta línea es crucial + } + # --- Ubicación para el frontend (raíz y cualquier otra ruta) --- location / { - # Ya no necesitamos la lógica de CORS aquí dentro. - proxy_pass http://frontend_public; + # Siempre añade la cabecera CORS para permitir el acceso desde cualquier origen. + # Esto es necesario para que 'extras.eldia.com' pueda cargar los scripts. + add_header 'Access-Control-Allow-Origin' '*' always; + + # Manejo de peticiones pre-vuelo (preflight) OPTIONS + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + + # Redirigimos al contenedor del frontend + proxy_pass http://mercados-frontend:80; 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; } }