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:
+35
-9
@@ -16,6 +16,8 @@ APP_HOST="remigracion.jumpingcrab.com"
|
||||
DEPLOY_ROOT="/opt/remigracion"
|
||||
VHOST_PATH="/etc/nginx/conf.d/remigracion.jumpingcrab.com.conf"
|
||||
BACKUP_DIR="/var/backups/nginx"
|
||||
TLS_CERT_PATH="/etc/letsencrypt/live/remigracion.jumpingcrab.com/fullchain.pem"
|
||||
ACME_WEBROOT="/var/www/letsencrypt"
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0" >&2
|
||||
@@ -55,6 +57,17 @@ artifact::require_build() {
|
||||
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() {
|
||||
local root="$1"
|
||||
|
||||
@@ -140,14 +153,23 @@ nginx::reload() {
|
||||
}
|
||||
|
||||
http::expect() {
|
||||
local url="$1"
|
||||
local expected="$2"
|
||||
local scheme="$1"
|
||||
local url="$2"
|
||||
local expected="$3"
|
||||
local port="80"
|
||||
local attempt
|
||||
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.
|
||||
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
|
||||
return 0
|
||||
fi
|
||||
@@ -160,14 +182,16 @@ http::expect() {
|
||||
http::verify() {
|
||||
local headers
|
||||
|
||||
http::expect "http://127.0.0.1/" "200"
|
||||
http::expect "http://127.0.0.1/robots.txt" "200"
|
||||
# HTTPS valida además la cadena y el nombre del certificado (sin -k).
|
||||
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
|
||||
fail "falta la cabecera X-Robots-Tag: noindex en la respuesta"
|
||||
fail "falta la cabecera X-Robots-Tag: noindex en la respuesta HTTPS"
|
||||
fi
|
||||
log "verificado: HTTP 200 y X-Robots-Tag: noindex"
|
||||
log "verificado: HTTP y HTTPS 200, certificado válido, X-Robots-Tag: noindex"
|
||||
}
|
||||
|
||||
main() {
|
||||
@@ -178,8 +202,10 @@ main() {
|
||||
host::require_root
|
||||
host::require_tools
|
||||
artifact::require_build "$root"
|
||||
tls::require_certificate
|
||||
|
||||
artifact::sync "$root"
|
||||
acme::prepare_webroot
|
||||
selinux::label
|
||||
|
||||
if vhost::install "$root"; then
|
||||
@@ -187,7 +213,7 @@ main() {
|
||||
fi
|
||||
|
||||
http::verify
|
||||
log "LISTO: http://$APP_HOST/ (sin TLS, no indexable)"
|
||||
log "LISTO: https://$APP_HOST/ (no indexable)"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user