diff --git a/ChatbotApi/Program.cs b/ChatbotApi/Program.cs index 7bc7520..211cd3f 100644 --- a/ChatbotApi/Program.cs +++ b/ChatbotApi/Program.cs @@ -20,8 +20,7 @@ builder.Services.AddCors(options => options.AddPolicy(name: myAllowSpecificOrigins, policy => { - //policy.WithOrigins("http://localhost:5173", "http://localhost:5174") - policy.WithOrigins("http://192.168.5.129:8081", "http://192.168.5.129:8082") + policy.WithOrigins("http://192.168.5.129:8081", "http://192.168.5.129:8082", "http://localhost:5173", "http://localhost:5174") .AllowAnyHeader() .AllowAnyMethod(); }); diff --git a/chatbot-admin/Dockerfile.admin b/chatbot-admin/Dockerfile.admin index a9292d3..b1ae532 100644 --- a/chatbot-admin/Dockerfile.admin +++ b/chatbot-admin/Dockerfile.admin @@ -9,7 +9,7 @@ RUN npm install COPY . . # Definimos la URL de la API para el panel de admin -RUN VITE_API_BASE_URL=http://192.168.5.129:8080 npm run build +RUN VITE_API_BASE_URL="" npm run build # ---- Etapa Final (Runtime) ---- FROM nginx:alpine AS final diff --git a/chatbot-widget/Dockerfile.widget b/chatbot-widget/Dockerfile.widget index f547b81..1f7feac 100644 --- a/chatbot-widget/Dockerfile.widget +++ b/chatbot-widget/Dockerfile.widget @@ -10,7 +10,7 @@ RUN npm install COPY . . # IMPORTANTE: Aquí definimos la URL de la API para producción # El docker-compose se encargará de exponer la API en el puerto 8080 del host -RUN VITE_API_BASE_URL=http://192.168.5.129:8080 npm run build +RUN VITE_API_BASE_URL="" npm run build # ---- Etapa Final (Runtime) ---- FROM nginx:alpine AS final diff --git a/docker-compose.yml b/docker-compose.yml index 2350bad..5c633f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,17 +5,13 @@ services: dockerfile: Dockerfile.api container_name: chatbot-api restart: unless-stopped - ports: - - "8080:80" # Mapea el puerto 80 del contenedor al 8080 de tu servidor Docker + env_file: ./.env # Usamos env_file para cargar todas las variables de .env environment: - # --- Variables de Entorno para la API --- - # Docker Compose las leerá automáticamente desde el archivo .env - - ASPNETCORE_ENVIRONMENT=Production - - ConnectionStrings__DefaultConnection=${DB_CONNECTION_STRING} - - Gemini__GeminiApiKey=${GEMINI_API_KEY} - - Jwt__Key=${JWT_KEY} - - Jwt__Issuer=${JWT_ISSUER} - - Jwt__Audience=${JWT_AUDIENCE} + - ASPNETCORE_URLS=http://+:80 # Forzamos a escuchar en el puerto 80 + expose: + - "80" + networks: + - chatbot-net chatbot-widget: build: @@ -23,8 +19,10 @@ services: dockerfile: Dockerfile.widget container_name: chatbot-widget restart: unless-stopped - ports: - - "8081:80" # Mapea el puerto 80 del contenedor Nginx al 8081 del host + expose: + - "80" + networks: + - chatbot-net chatbot-admin: build: @@ -32,9 +30,29 @@ services: dockerfile: Dockerfile.admin container_name: chatbot-admin restart: unless-stopped + expose: + - "80" + networks: + - chatbot-net + + proxy: + image: nginx:1.25-alpine + container_name: chatbot-proxy + restart: unless-stopped + volumes: + - ./proxy/nginx.conf:/etc/nginx/conf.d/default.conf ports: - - "8082:80" # Mapea el puerto 80 del contenedor Nginx al 8082 del host + # Puerto para el widget y la API + - "8081:80" + # Puerto para el panel de administración + - "8082:81" + networks: + - chatbot-net + depends_on: + - chatbot-api + - chatbot-widget + - chatbot-admin networks: - default: + chatbot-net: driver: bridge \ No newline at end of file diff --git a/proxy/nginx.conf b/proxy/nginx.conf new file mode 100644 index 0000000..9bb2d9a --- /dev/null +++ b/proxy/nginx.conf @@ -0,0 +1,51 @@ +# /proxy/nginx.conf + +# 1. Definimos los "upstreams", que son nuestros servicios de backend. +# Nginx usará los nombres de servicio definidos en docker-compose. +upstream api_server { + server chatbot-api:80; +} + +upstream widget_server { + server chatbot-widget:80; +} + +upstream admin_server { + server chatbot-admin:80; +} + +# 2. Servidor para la API y el Widget +server { + listen 80; # Puerto de escucha para el tráfico principal (API y Widget) + + # Regla para la API: si la URL empieza con /api/, reenvíala al contenedor de la API. + location /api/ { + proxy_pass http://api_server; + 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; + } + + # Regla para el Widget: si es cualquier otra cosa, asume que es para el widget. + location / { + proxy_pass http://widget_server; + 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; + } +} + +# 3. Servidor separado para el Panel de Administración +server { + listen 81; # Puerto de escucha para el tráfico del panel de admin + + location / { + proxy_pass http://admin_server; + 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; + } +} \ No newline at end of file