En este tutorial veremos como poner en funcionamiento de forma rápida un servidor web(http/https) por CLI con una web de mantenimiento.
Esto nos resultará muy útil para no dejar la web fallando si algo sale mal en alguna actualización del SO o de la jail(contenedor).
El primer paso es cambiar el DNS al servidor donde montemos el servidor temporal, o si es una red casera cambiar la redirección de los puertos 80/443 a la ip del servidor temporal:
Entraremos al panel de gestión de configuración del DNS del proveedor en cuestión.
IP_ROUTER
Internet -> Seguridad: Port Forwarding
80:
IP_SERVER_MANTENIMIENTO:80 -> IP_SERVIDOR_TEMPORAL:80
443:
IP_SERVER_MANTENIMIENTO:443 -> IP_SERVIDOR_TEMPORAL:443
El servidor por CLI que vamos a utilizar está escrito en NodeJS
así que instalamos NPM
y Certbot
para poder expedir el certificado SSL:
pkg install npm py311-certbot
apt install npm certbot
Obtenemos el certificado:
certbot certonly --standalone -d alfaexploit.com --non-interactive --agree-tos --email kr0m@alfaexploit.com --no-eff-email
Deberíamos de obtener los ficheros en los siguientes paths:
Certificate is saved at: /usr/local/etc/letsencrypt/live/alfaexploit.com/fullchain.pem
Key is saved at: /usr/local/etc/letsencrypt/live/alfaexploit.com/privkey.pem
Certificate is saved at: /etc/letsencrypt/live/alfaexploit.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/alfaexploit.com/privkey.pem
Creamos la web que mostraremos durante el mantenimiento:
mkdir maintenanceWeb/
vi maintenanceWeb/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Maintenance</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.maintenance-container {
text-align: center;
}
.maintenance-container img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<div class="maintenance-container">
<img src="https://i.pinimg.com/736x/0f/d1/6a/0fd16a96935380b59961d43ea5234320.jpg" alt="Maintenance Image">
<h1>We are under maintenance</h1>
<p>We will be back soon. Thank you for your patience.</p>
</div>
</body>
</html>
Arrancamos en una consola el servidor en el puerto 80:
npx http-server maintenanceWeb/ -p 80
Arrancamos en otra consola el servidor en el puerto 443 donde debemos indicar el path a los ficheros obtenidos mediante Certbot
:
npx http-server maintenanceWeb/ -p 443 --ssl --cert /usr/local/etc/letsencrypt/live/alfaexploit.com/fullchain.pem --key /usr/local/etc/letsencrypt/live/alfaexploit.com/privkey.pem
npx http-server maintenanceWeb/ -p 443 --ssl --cert /etc/letsencrypt/live/alfaexploit.com/fullchain.pem --key /etc/letsencrypt/live/alfaexploit.com/privkey.pem