Add apache2-vhost-https.md
This commit is contained in:
commit
86712ab81a
233
apache2-vhost-https.md
Normal file
233
apache2-vhost-https.md
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
### Com protegir Apache amb Let’s Encrypt en Debian 12, 11 o 10
|
||||||
|
|
||||||
|
|
||||||
|
**Introducció**
|
||||||
|
|
||||||
|
Assegurar el servidor web Apache amb un certificat de Let’s Encrypt és essencial per protegir el teu lloc web i dades. Aquesta guia t'ajudarà a fer-ho en Debian 12, 11 i 10, enfocant-se en implementar mesures de seguretat robustes mentre es simplifiquen les complexitats de la gestió del servidor.
|
||||||
|
|
||||||
|
|
||||||
|
### Avantatges d'utilitzar Let’s Encrypt amb Apache en Debian
|
||||||
|
|
||||||
|
1. **Cost-efectiu**: Certificats SSL gratuïts accessibles per a tothom.
|
||||||
|
|
||||||
|
2. **Renovacions automatitzades**: Simplifica l’obtenció i renovació de certificats, minimitzant riscos de falles de seguretat.
|
||||||
|
|
||||||
|
3. **Seguretat millorada**: Forta xifra de dades en trànsit, augmentant la seguretat general.
|
||||||
|
|
||||||
|
4. **Ampla compatibilitat**: La majoria de navegadors moderns reconeixen certificats de Let’s Encrypt.
|
||||||
|
|
||||||
|
5. **Mesures de seguretat proactives**: Actualitzacions regulars i polítiques estrictes contra amenaces cibernètiques.
|
||||||
|
|
||||||
|
|
||||||
|
### Instal·lar Certbot per Apache
|
||||||
|
|
||||||
|
**Actualitzar repositoris de paquets abans de la instal·lar Certbot**
|
||||||
|
|
||||||
|
Executa els següents comandaments per assegurar que el sistema està actualitzat:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo apt update
|
||||||
|
|
||||||
|
sudo apt upgrade
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Instal·lar Certbot i el plugin d'Apache**
|
||||||
|
|
||||||
|
Per instal·lar Certbot i el plugin d'Apache, executa:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo apt install certbot python3-certbot-apache
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Configurar Apache i el certificat de Let’s Encrypt
|
||||||
|
|
||||||
|
Guia per configurar Apache i generar un certificat SSL de Let’s Encrypt utilitzant Certbot.
|
||||||
|
|
||||||
|
|
||||||
|
**Configuració de Certbot i generació de certificat SSL**
|
||||||
|
|
||||||
|
Després d'instal·lar Certbot, executa la següent ordre per generar un certificat SSL:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d yourdomain.com
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Altres opcions interactivas de Certbot**
|
||||||
|
|
||||||
|
Si prefereixes un enfocament més interactiu:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo certbot --apache
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Seguiràs uns passos GUI de configuració.
|
||||||
|
|
||||||
|
|
||||||
|
### Automitzar la renovació del certificat SSL amb Cron
|
||||||
|
|
||||||
|
**Comprovació prèvia de la renovació**
|
||||||
|
|
||||||
|
Realitza un simulacre de renovació:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo certbot renew --dry-run
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Programar renovacions automàtiques**
|
||||||
|
|
||||||
|
Obre el fitxer crontab:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo crontab -e
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Afegeix la següent línia per programar la renovació diària a les 2:30 AM:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
30 2 * * * /usr/bin/certbot renew --quiet
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Millorar la configuració SSL d'Apache
|
||||||
|
|
||||||
|
**Editar el fitxer de configuració d'Apache**
|
||||||
|
|
||||||
|
Obre el fitxer de configuració del teu domini:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo nano /etc/apache2/sites-available/your_domain.conf
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Redirigir HTTP a HTTPS**
|
||||||
|
|
||||||
|
Afegeix la regla per redirigir tot el trànsit HTTP a HTTPS:
|
||||||
|
|
||||||
|
|
||||||
|
```apache
|
||||||
|
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
|
||||||
|
|
||||||
|
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Habilitar SSL i especificar certificats**
|
||||||
|
|
||||||
|
Afegeix:
|
||||||
|
|
||||||
|
|
||||||
|
```apache
|
||||||
|
|
||||||
|
SSLEngine on
|
||||||
|
|
||||||
|
SSLCertificateFile /path/to/signed_cert_and_intermediate_certs
|
||||||
|
|
||||||
|
SSLCertificateKeyFile /path/to/private_key
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Habilitar HTTP/2**
|
||||||
|
|
||||||
|
Afegeix:
|
||||||
|
|
||||||
|
|
||||||
|
```apache
|
||||||
|
|
||||||
|
Protocols h2 http/1.1
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Implementar HSTS**
|
||||||
|
|
||||||
|
Afegeix:
|
||||||
|
|
||||||
|
|
||||||
|
```apache
|
||||||
|
|
||||||
|
Header always set Strict-Transport-Security "max-age=63072000"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Configurar protocols i xifres SSL**
|
||||||
|
|
||||||
|
Defineix protocols segurs i xifres adequades:
|
||||||
|
|
||||||
|
|
||||||
|
```apache
|
||||||
|
|
||||||
|
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
|
||||||
|
|
||||||
|
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Habilitar OCSP Stapling**
|
||||||
|
|
||||||
|
Afegeix:
|
||||||
|
|
||||||
|
|
||||||
|
```apache
|
||||||
|
|
||||||
|
SSLUseStapling On
|
||||||
|
|
||||||
|
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
**Validar i aplicar els canvis**
|
||||||
|
|
||||||
|
Comprova la configuració:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo apachectl configtest
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Recarrega Apache si no hi ha errors:
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
sudo systemctl restart apache2
|
||||||
Loading…
Reference in New Issue
Block a user