diff --git a/web/NGINX_CONFIG.md b/web/NGINX_CONFIG.md index 48926e8..67ad622 100644 --- a/web/NGINX_CONFIG.md +++ b/web/NGINX_CONFIG.md @@ -47,6 +47,7 @@ nginx dashboard → /usr/share/nginx/html/dashboard/assets/index-abc123.js - **Astro config**: Sin base (raíz por defecto) - **Nginx interno**: Sirve desde `/usr/share/nginx/html/` +- **Nginx config**: `web/landing/nginx.conf` - **Assets**: Se construyen para la raíz **Flujo de peticiones**: @@ -58,6 +59,15 @@ nginx proxy → http://landing:80/ nginx landing → /usr/share/nginx/html/index.html ``` +**Assets (ej: logo.jpg)**: +``` +Usuario → http://localhost/logo.jpg + ↓ +nginx proxy → http://landing:80/logo.jpg + ↓ +nginx landing → /usr/share/nginx/html/logo.jpg +``` + ## Puertos ### Desarrollo local diff --git a/web/dashboard/nginx-dashboard.conf b/web/dashboard/nginx-dashboard.conf index a34e830..04d93ff 100644 --- a/web/dashboard/nginx-dashboard.conf +++ b/web/dashboard/nginx-dashboard.conf @@ -1,7 +1,7 @@ server { listen 80; server_name localhost; - root /usr/share/nginx/html; + root /usr/share/nginx/html/dashboard; index index.html; # Gzip compression @@ -10,22 +10,16 @@ server { gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript; - # Dashboard assets con prefijo /dashboard/ - location /dashboard/ { - # Cache static assets - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { - expires 1y; - add_header Cache-Control "public, immutable"; - try_files $uri =404; - } - - # SPA routing - todas las rutas del dashboard - try_files $uri $uri/ /dashboard/index.html; + # Cache static assets ANTES de SPA routing + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + try_files $uri =404; } - # Redirigir raíz al dashboard - location = / { - return 301 /dashboard/; + # SPA routing - todo desde la raíz del contenedor + location / { + try_files $uri $uri/ /index.html; } } diff --git a/web/dashboard/nginx.conf b/web/dashboard/nginx.conf index a34e830..04d93ff 100644 --- a/web/dashboard/nginx.conf +++ b/web/dashboard/nginx.conf @@ -1,7 +1,7 @@ server { listen 80; server_name localhost; - root /usr/share/nginx/html; + root /usr/share/nginx/html/dashboard; index index.html; # Gzip compression @@ -10,22 +10,16 @@ server { gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript; - # Dashboard assets con prefijo /dashboard/ - location /dashboard/ { - # Cache static assets - location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { - expires 1y; - add_header Cache-Control "public, immutable"; - try_files $uri =404; - } - - # SPA routing - todas las rutas del dashboard - try_files $uri $uri/ /dashboard/index.html; + # Cache static assets ANTES de SPA routing + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + try_files $uri =404; } - # Redirigir raíz al dashboard - location = / { - return 301 /dashboard/; + # SPA routing - todo desde la raíz del contenedor + location / { + try_files $uri $uri/ /index.html; } } diff --git a/web/landing/Dockerfile b/web/landing/Dockerfile index e2adf21..10340e7 100644 --- a/web/landing/Dockerfile +++ b/web/landing/Dockerfile @@ -20,6 +20,9 @@ FROM nginx:alpine # Copiar archivos construidos a la raíz COPY --from=builder /app/dist /usr/share/nginx/html +# Copiar configuración de nginx +COPY nginx.conf /etc/nginx/conf.d/default.conf + # Exponer puerto EXPOSE 80 diff --git a/web/landing/nginx.conf b/web/landing/nginx.conf new file mode 100644 index 0000000..1d5492b --- /dev/null +++ b/web/landing/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 80; + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + # Gzip compression + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript image/svg+xml; + + # Cache static assets + location ~* \.(jpg|jpeg|png|gif|ico|svg|css|js|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } + + # Serve static files + location / { + try_files $uri $uri/ /index.html; + } +} + diff --git a/web/nginx.conf b/web/nginx.conf index 2a7d3f7..2182d8f 100644 --- a/web/nginx.conf +++ b/web/nginx.conf @@ -33,8 +33,11 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } - # Dashboard Vue - pasar petición completa con prefijo /dashboard - location /dashboard { + # Dashboard Vue - reescribir /dashboard/* a /* en el contenedor + location /dashboard/ { + # Quitar el prefijo /dashboard antes de pasar al contenedor + rewrite ^/dashboard/?(.*)$ /$1 break; + proxy_pass http://dashboard:80; proxy_http_version 1.1; proxy_set_header Host $host;