In this tutorial, we will see how to quickly set up a web server (http/https) via CLI with a maintenance web page.
This will be very useful to avoid leaving the web page down if something goes wrong during an OS or jail (container) update.
The first step is to change the DNS to the server where we set up the temporary server, or if it is a home network, change the port forwarding of ports 80/443 to the IP of the temporary server:
We will enter the DNS configuration management panel of the provider in question.
The CLI server we will use is written in NodeJS
, so we install NPM
and Certbot
to issue the SSL certificate:
pkg install npm py311-certbot
Obtain the certificate:
certbot certonly --standalone -d alfaexploit.com --non-interactive --agree-tos --email kr0m@alfaexploit.com --no-eff-email
The files should be saved in the following 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
Create the web page that will be displayed during maintenance:
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>
Start the server on port 80 in one console:
npx http-server maintenanceWeb/ -p 80
Start the server on port 443 in another console, specifying the path to the files obtained via 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