fix(deploy): sirve también por HTTPS con Let's Encrypt (y el puerto 80 no redirige)
El navegador (HSTS/HTTPS-First de Chrome) forzaba https:// y recibía el certificado de localesp.es (default_server 443): de ahí el "me redirige a https". El DNS sí permite ACME, así que se emite certificado real. - deploy/nginx.conf: un único server block con listen 80 y 443; así las reglas anti-indexación (X-Robots-Tag, 403 a rastreadores, robots.txt inline y fallback SPA) no se duplican. El puerto 80 sigue sirviendo la app sin redirección. - location ^~ /.well-known/acme-challenge/ con root /var/www/letsencrypt: el webroot ACME queda fuera del árbol desplegado para que el 'rsync --delete' no borre el challenge durante una renovación. - scripts/deploy.sh: exige el certificado antes de tocar nada, crea el webroot, y verifica 200 en HTTP y HTTPS validando la cadena y el nombre del certificado (curl --resolve, sin -k) además de X-Robots-Tag. - README: TLS, rutas del certificado y del webroot; ya no hay aviso de "sin TLS a propósito".
This commit is contained in:
@@ -60,11 +60,14 @@ El JSON tiene tres claves:
|
|||||||
|
|
||||||
## Despliegue
|
## Despliegue
|
||||||
|
|
||||||
Entorno de previsualización privado en **<http://remigracion.jumpingcrab.com/>**
|
Entorno de previsualización privado en **<https://remigracion.jumpingcrab.com/>**
|
||||||
(mismo host que `localesp.es` y `git.localesp.es`).
|
(mismo host que `localesp.es` y `git.localesp.es`).
|
||||||
|
|
||||||
- **Sin TLS a propósito:** el DNS de `remigracion.jumpingcrab.com` no permite
|
- **HTTP y HTTPS:** el vhost escucha en 80 y 443 (mismo `server` block, así
|
||||||
emitir un certificado Let's Encrypt, así que se sirve sólo por HTTP.
|
que las reglas anti-indexación no se duplican). Certificado Let's Encrypt
|
||||||
|
emitido con webroot en `/var/www/letsencrypt` y renovado por
|
||||||
|
`certbot-renew.timer`; el `--deploy-hook` recarga nginx. El puerto 80 no
|
||||||
|
redirige a 443: sirve la app igual.
|
||||||
- **No indexable:** el entorno no debe aparecer en buscadores, agregadores ni
|
- **No indexable:** el entorno no debe aparecer en buscadores, agregadores ni
|
||||||
crawlers de IA. Se aplica en tres capas independientes:
|
crawlers de IA. Se aplica en tres capas independientes:
|
||||||
1. nginx devuelve `403` a los user-agents de rastreadores conocidos.
|
1. nginx devuelve `403` a los user-agents de rastreadores conocidos.
|
||||||
@@ -85,6 +88,8 @@ Artefactos y servicios en el host (mismo patrón que
|
|||||||
|---|---|
|
|---|---|
|
||||||
| Build estático (raíz de nginx) | `/opt/remigracion/dist` |
|
| Build estático (raíz de nginx) | `/opt/remigracion/dist` |
|
||||||
| vhost nginx (fuente en `deploy/nginx.conf`) | `/etc/nginx/conf.d/remigracion.jumpingcrab.com.conf` |
|
| vhost nginx (fuente en `deploy/nginx.conf`) | `/etc/nginx/conf.d/remigracion.jumpingcrab.com.conf` |
|
||||||
|
| Certificado Let's Encrypt | `/etc/letsencrypt/live/remigracion.jumpingcrab.com/` |
|
||||||
|
| Webroot ACME | `/var/www/letsencrypt` |
|
||||||
| Script de despliegue | `scripts/deploy.sh` |
|
| Script de despliegue | `scripts/deploy.sh` |
|
||||||
|
|
||||||
Despliegue manual:
|
Despliegue manual:
|
||||||
@@ -94,9 +99,10 @@ npm ci && npm run build
|
|||||||
sudo bash scripts/deploy.sh
|
sudo bash scripts/deploy.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
El script sincroniza `dist/`, etiqueta el árbol para SELinux
|
El script sincroniza `dist/`, crea el webroot ACME, etiqueta el árbol para
|
||||||
(`httpd_sys_content_t`), instala el vhost si cambió (con rollback si
|
SELinux (`httpd_sys_content_t`), instala el vhost si cambió (con rollback si
|
||||||
`nginx -t` falla), recarga nginx y verifica `200` + `X-Robots-Tag`.
|
`nginx -t` falla), recarga nginx y verifica `200` en HTTP y HTTPS (validando
|
||||||
|
el certificado) más la cabecera `X-Robots-Tag`.
|
||||||
|
|
||||||
## Próximos pasos
|
## Próximos pasos
|
||||||
|
|
||||||
|
|||||||
+21
-4
@@ -1,18 +1,27 @@
|
|||||||
# remigracion.jumpingcrab.com — entorno privado de previsualización.
|
# remigracion.jumpingcrab.com — entorno privado de previsualización.
|
||||||
#
|
#
|
||||||
# Sin TLS a propósito: el DNS de este dominio no permite emitir un certificado
|
# Sirve el build estático de Vite desde /opt/remigracion/dist por HTTP y HTTPS
|
||||||
# Let's Encrypt, así que se sirve sólo por HTTP.
|
# en el mismo server block. El certificado lo emite certbot con webroot en
|
||||||
|
# /var/www/letsencrypt y se renueva con el timer del sistema (el deploy-hook
|
||||||
|
# del certificado recarga nginx).
|
||||||
#
|
#
|
||||||
# No indexación (objetivo doble):
|
# No indexación (objetivo doble):
|
||||||
# 1. Cabecera X-Robots-Tag en TODAS las respuestas (incluidos 4xx/5xx).
|
# 1. 403 en el borde a los rastreadores conocidos, antes de servir nada.
|
||||||
# 2. 403 en el borde a los rastreadores conocidos, antes de servir nada.
|
# 2. Cabecera X-Robots-Tag en TODAS las respuestas (incluidos 4xx/5xx).
|
||||||
# El bundle también declara <meta name="robots"> y sirve un robots.txt
|
# El bundle también declara <meta name="robots"> y sirve un robots.txt
|
||||||
# con "Disallow: /" (ver public/robots.txt e index.html).
|
# con "Disallow: /" (ver public/robots.txt e index.html).
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
|
listen 443 ssl http2;
|
||||||
|
listen [::]:443 ssl http2;
|
||||||
server_name remigracion.jumpingcrab.com;
|
server_name remigracion.jumpingcrab.com;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/remigracion.jumpingcrab.com/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/remigracion.jumpingcrab.com/privkey.pem;
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
|
||||||
root /opt/remigracion/dist;
|
root /opt/remigracion/dist;
|
||||||
index index.html;
|
index index.html;
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
@@ -26,6 +35,14 @@ server {
|
|||||||
return 403;
|
return 403;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Validación ACME de certbot. Vive fuera del árbol desplegado para que el
|
||||||
|
# 'rsync --delete' del deploy no borre el challenge a mitad de una renovación.
|
||||||
|
location ^~ /.well-known/acme-challenge/ {
|
||||||
|
root /var/www/letsencrypt;
|
||||||
|
default_type "text/plain";
|
||||||
|
add_header X-Robots-Tag "noindex, nofollow" always;
|
||||||
|
}
|
||||||
|
|
||||||
# robots.txt generado aquí mismo: el deploy no depende del build para esto.
|
# robots.txt generado aquí mismo: el deploy no depende del build para esto.
|
||||||
location = /robots.txt {
|
location = /robots.txt {
|
||||||
add_header Content-Type "text/plain; charset=utf-8" always;
|
add_header Content-Type "text/plain; charset=utf-8" always;
|
||||||
|
|||||||
+35
-9
@@ -16,6 +16,8 @@ APP_HOST="remigracion.jumpingcrab.com"
|
|||||||
DEPLOY_ROOT="/opt/remigracion"
|
DEPLOY_ROOT="/opt/remigracion"
|
||||||
VHOST_PATH="/etc/nginx/conf.d/remigracion.jumpingcrab.com.conf"
|
VHOST_PATH="/etc/nginx/conf.d/remigracion.jumpingcrab.com.conf"
|
||||||
BACKUP_DIR="/var/backups/nginx"
|
BACKUP_DIR="/var/backups/nginx"
|
||||||
|
TLS_CERT_PATH="/etc/letsencrypt/live/remigracion.jumpingcrab.com/fullchain.pem"
|
||||||
|
ACME_WEBROOT="/var/www/letsencrypt"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0" >&2
|
echo "Usage: $0" >&2
|
||||||
@@ -55,6 +57,17 @@ artifact::require_build() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# El vhost sirve HTTP y HTTPS: sin certificado nginx -t fallaría.
|
||||||
|
tls::require_certificate() {
|
||||||
|
if [ ! -f "$TLS_CERT_PATH" ]; then
|
||||||
|
fail "falta el certificado $TLS_CERT_PATH — emitelo con: certbot certonly --webroot -w $ACME_WEBROOT -d $APP_HOST --deploy-hook 'systemctl reload nginx'"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
acme::prepare_webroot() {
|
||||||
|
mkdir -p "$ACME_WEBROOT"
|
||||||
|
}
|
||||||
|
|
||||||
artifact::sync() {
|
artifact::sync() {
|
||||||
local root="$1"
|
local root="$1"
|
||||||
|
|
||||||
@@ -140,14 +153,23 @@ nginx::reload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
http::expect() {
|
http::expect() {
|
||||||
local url="$1"
|
local scheme="$1"
|
||||||
local expected="$2"
|
local url="$2"
|
||||||
|
local expected="$3"
|
||||||
|
local port="80"
|
||||||
local attempt
|
local attempt
|
||||||
local code
|
local code
|
||||||
|
|
||||||
|
if [ "$scheme" = "https" ]; then
|
||||||
|
port="443"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Se resuelve el dominio a loopback: prueba el vhost correcto y, en HTTPS,
|
||||||
|
# la cadena y el nombre del certificado (sin -k).
|
||||||
# nginx recarga en segundo plano: se reintenta antes de dar el deploy por fallido.
|
# nginx recarga en segundo plano: se reintenta antes de dar el deploy por fallido.
|
||||||
for attempt in $(seq 1 15); do
|
for attempt in $(seq 1 15); do
|
||||||
code="$(curl -s -o /dev/null -m 5 -w '%{http_code}' -H "Host: $APP_HOST" "$url" || true)"
|
code="$(curl -s -o /dev/null -m 5 -w '%{http_code}' \
|
||||||
|
--resolve "$APP_HOST:$port:127.0.0.1" "$url" 2>/dev/null || true)"
|
||||||
if [ "$code" = "$expected" ]; then
|
if [ "$code" = "$expected" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -160,14 +182,16 @@ http::expect() {
|
|||||||
http::verify() {
|
http::verify() {
|
||||||
local headers
|
local headers
|
||||||
|
|
||||||
http::expect "http://127.0.0.1/" "200"
|
# HTTPS valida además la cadena y el nombre del certificado (sin -k).
|
||||||
http::expect "http://127.0.0.1/robots.txt" "200"
|
http::expect "http" "http://$APP_HOST/" "200"
|
||||||
|
http::expect "https" "https://$APP_HOST/" "200"
|
||||||
|
http::expect "http" "http://$APP_HOST/robots.txt" "200"
|
||||||
|
|
||||||
headers="$(curl -sI -m 10 -H "Host: $APP_HOST" "http://127.0.0.1/" | tr -d '\r')"
|
headers="$(curl -sI -m 10 --resolve "$APP_HOST:443:127.0.0.1" "https://$APP_HOST/" | tr -d '\r')"
|
||||||
if ! grep -qi '^X-Robots-Tag:.*noindex' <<< "$headers"; then
|
if ! grep -qi '^X-Robots-Tag:.*noindex' <<< "$headers"; then
|
||||||
fail "falta la cabecera X-Robots-Tag: noindex en la respuesta"
|
fail "falta la cabecera X-Robots-Tag: noindex en la respuesta HTTPS"
|
||||||
fi
|
fi
|
||||||
log "verificado: HTTP 200 y X-Robots-Tag: noindex"
|
log "verificado: HTTP y HTTPS 200, certificado válido, X-Robots-Tag: noindex"
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
@@ -178,8 +202,10 @@ main() {
|
|||||||
host::require_root
|
host::require_root
|
||||||
host::require_tools
|
host::require_tools
|
||||||
artifact::require_build "$root"
|
artifact::require_build "$root"
|
||||||
|
tls::require_certificate
|
||||||
|
|
||||||
artifact::sync "$root"
|
artifact::sync "$root"
|
||||||
|
acme::prepare_webroot
|
||||||
selinux::label
|
selinux::label
|
||||||
|
|
||||||
if vhost::install "$root"; then
|
if vhost::install "$root"; then
|
||||||
@@ -187,7 +213,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
http::verify
|
http::verify
|
||||||
log "LISTO: http://$APP_HOST/ (sin TLS, no indexable)"
|
log "LISTO: https://$APP_HOST/ (no indexable)"
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user