Stop publishing web on host port 8080, which clashed between stacks; Traefik reaches port 80 of the container through dokploy-network. Local testing now uses docker-compose.local.yml to publish the port. Proxy nginx to a `gruperly-api` alias that only exists on the stack's own network: the `api` service name is also registered on dokploy-network, so with two stacks nginx could reach the other environment's API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.0 KiB
Nginx Configuration File
73 lines
3.0 KiB
Nginx Configuration File
# Nginx para el build de @gruperly/web.
|
|
# Sirve los assets estáticos y hace de proxy de /api hacia el servicio `api`.
|
|
# Con el proxy, el navegador pega siempre al mismo origen: la cookie de sesión
|
|
# es first-party y el CORS del backend queda como red de seguridad.
|
|
|
|
# DNS interno de Docker: resuelve `gruperly-api` en cada request, así el proxy
|
|
# sobrevive a un recreate del contenedor (que cambia la IP). Es un alias que el
|
|
# compose define solo en la red propia del stack; `api` también existe en
|
|
# dokploy-network y con dev y prod en el mismo server resolvería a cualquiera.
|
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
client_max_body_size 10m;
|
|
|
|
# ── API ────────────────────────────────────────────────────────────────────
|
|
location /api/ {
|
|
set $api http://gruperly-api:4000;
|
|
proxy_pass $api$request_uri;
|
|
|
|
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;
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
proxy_set_header Connection "";
|
|
|
|
proxy_connect_timeout 10s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
|
|
# ── Assets con hash en el nombre ───────────────────────────────────────────
|
|
# Solo `add_header`: `expires` agregaría un segundo Cache-Control.
|
|
location /assets/ {
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# ── Service worker y manifest ─────────────────────────────────────────────
|
|
# Nunca se cachean: el navegador tiene que ver la versión nueva en el próximo
|
|
# load. `=404` y no el fallback del SPA, porque un 404 del SW debe ser un 404.
|
|
location = /manifest.webmanifest {
|
|
# `mime.types` de alpine no conoce `webmanifest` y lo sirve como
|
|
# octet-stream. Un `types` acá reemplaza el mapa heredado, pero esta location
|
|
# solo sirve un archivo, así que no puede romper nada más.
|
|
types { application/manifest+json webmanifest; }
|
|
default_type application/manifest+json;
|
|
add_header Cache-Control "no-cache";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
location ~ ^/(sw\.js|workbox-[^/]+\.js)$ {
|
|
add_header Cache-Control "no-cache";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# ── SPA ────────────────────────────────────────────────────────────────────
|
|
location = /index.html {
|
|
add_header Cache-Control "no-cache";
|
|
}
|
|
|
|
location / {
|
|
add_header Cache-Control "no-cache";
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|