Servidor
WEB
nginx
web encriptada
nginx
web encriptada
El servidor que tengo montado en una Raspberry no tiene ningún secreto y ningún formulario, y es del tipo estático.
No he visto nunca en la necesidad de encriptar la página web por lo que hasta ahora respondía al puerto 80.
Resulta que algunos amigos me decían que les era difícil acceder a mi página desde sus navegadores.
Mirando lo que les podía pasar, resultó que algunos navegadores venían por defecto que bloqueaban las páginas no encriptadas y las daban como no seguras.
Después de permitir en el navegador la excepción de aceptar esa dirección de página, cargaba bien la página.
En este proyecto explico como activar la encriptación en el servidor nginx de mi página web.
Sin tener ni idea de como hacerlo, me puse a navegar por la red buscando tutoriales, y este es un resumen de como hacerlo.
Voy a empezar por el final, configurar el router de acceso al exterior, este fue un error que tuve y que me llevo tiempo, muchos tutoriales no lo explican.

Al igual que se hace con una página clásica que direcciona el puerto 80 a nuestro servidor, también hay que hacerlo con el puerto 443.
Vamos a utilizar una aplicación que se llama Certbot. Es una herramienta creada por la Electronic Frontier Foundation (EFF) para facilitar la obtención, instalación y renovación de estos certificados.
El siguiente paso es teclear como root las siguientes ordenes.
| sudo add-apt-repository
ppa:certbot/certbot sudo apt-get install certbot python-certbot-nginx Si nos da un error de que no encuentra python-certbot-nginx lo cambiamos por: sudo apt-get install certbot python3-certbot-nginx sudo systemctl restart nginx Ahora no toca ejecutar el programa certbot certbot --nginx -d seta43.duckdns.org |
Deberemos de responder a una serie de preguntas, yo respondo que Yes a todas.
root@deb112:/home/seta# certbot --nginx -d seta43.duckdns.org Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): xsetaseta@gmail.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.8-July-06-2026.pdf. You must agree in order to register with the ACME server. Do you agree? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y Account registered. Requesting a certificate for seta43.duckdns.org Performing the following challenges: http-01 challenge for seta43.duckdns.org Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/default - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://seta43.duckdns.org - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Subscribe to the EFF mailing list (email: xsetaseta@gmail.com). IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/seta43.duckdns.org/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/seta43.duckdns.org/privkey.pem Your certificate will expire on 2027-01-12. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
También nos modificara el fichero /etc/nginx/sites-available/default de nginx que añadirá la escucha al puerto 443.
Se puede utilizar el fichero default de nginx con los cambios que realizó certbot , pero está un tanto desordenado todo.
Yo he quitado las líneas de comentar, y lo he ordenado un poco.
| # Redirigir tráfico HTTP (puerto 80) a
HTTPS (puerto 443) server { listen 80; server_name seta43.duckdns.org; root /var/www/html; index index.html index.htm; return 301 https://$host$request_uri; } # Configuración del servidor HTTPS server { root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name seta43.duckdns.org; # managed by Certbot location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } listen [::]:443 ssl ipv6only=on; # managed by Certbot listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/seta43.duckdns.org/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/seta43.duckdns.org/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } |
Ahora solo nos que reiniciar el servidor y comprobar que el servidor sirve la páginas web encriptadas, tanto internamente como desde el exterior.
sudo systemctl restart nginx

Aviso: A los 9 meses caduca el certificado, y debemos renovarlo.
Todo esto lo he probado con mi Raspberry Pi de 512 MB de RAM - Debian 9 (modo consola), y con mi PC con Debian 11.
Saludos
Juan Galaz
Bibliografía:
https://programacionymas.com/blog/obtener-certificado-ssl-certbot
https://alexhost.com/es/faq/how-to-set-up-an-ssl-certificate-on-nginx/
https://rdr-it.com/es/nginx-generar-un-certificado-de-lets-encrypt-con-certbot/