Configura il supporto HTTPS con Let's Encrypt

:bookmark: Questa è una guida per abilitare HTTPS su un’installazione esistente di Discourse utilizzando Let’s Encrypt. Si presume un’installazione precedente senza HTTPS abilitato.

:person_raising_hand: Livello utente richiesto: Amministratore di sistema

:exclamation: Questa guida è valida solo per installazioni esistenti in cui HTTPS non è abilitato. Seguendo la guida ufficiale di configurazione, HTTPS viene abilitato automaticamente per impostazione predefinita.

Quindi vorresti aggiungere https al tuo Discourse completamente gratuito, grazie ai nostri amici di Let’s Encrypt?

:bell: Tutto il resto del tuo sito è pronto per HTTPS?

Prima di iniziare, tieni presente che affinché HTTPS funzioni correttamente, ogni singola risorsa nella pagina deve essere compatibile con HTTPS. Considera il tuo CDN, i tuoi login social, i file del logo, qualsiasi JavaScript di terze parti, immagini, font o CSS — tutti questi devono essere disponibili tramite HTTPS!

Nota: ./discourse-setup abilita Let’s Encrypt. A partire da marzo 2017, puoi eseguirlo di nuovo, premere invio alcune volte e inserire il tuo indirizzo email; lo script includerà i modelli necessari e inserirà il tuo indirizzo email come richiesto. A meno che tu non sia un sysadmin esperto e non abbia una ragione per non farlo, dovresti eseguire discourse-setup piuttosto che leggere oltre. (Se hai installato Discourse molto tempo fa, potresti dover ancora modificare app.yml manualmente.)

Nota: Se il tuo Discourse è accessibile tramite un proxy inverso (ad esempio Cloudflare), questa configurazione non funzionerà.

Configura HTTPS con Let’s Encrypt

1. Modifica app.yml

Accedi al file di configurazione del tuo Discourse:

cd /var/discourse
nano containers/app.yml
  • Aggiungi i seguenti modelli:
    templates:
      - "templates/web.template.yml"
      - "templates/web.ssl.template.yml"
      - "templates/web.letsencrypt.ssl.template.yml"
    

:warning: Discourse è l’unico sito web sul tuo server?

Se stai già utilizzando web.socketed.template.yml, perché ospiti altri siti web tramite la porta 80 sullo stesso server, fermati. Dovresti utilizzare un client Let’s Encrypt sul sistema host; la convalida fallirà poiché il client utilizzato non può associarsi alle socket necessarie.

2. Esponi le porte HTTPS

Assicurati che le seguenti porte siano esposte per il traffico HTTPS:

expose:
  - "80:80"
  - "443:443"

3. Aggiungi l’email per Let’s Encrypt

Inserisci l’indirizzo email per le notifiche di Let’s Encrypt:

env:
  LETSENCRYPT_ACCOUNT_EMAIL: 'tuo-email@esempio.com'

4. Ricompila l’applicazione

Applica le modifiche ricompilando il contenitore:

./launcher rebuild app

5. Convalida HTTPS

Accedi al tuo sito tramite https://tuodominio.com. In caso di successo, vedrai il tuo sito protetto da HTTPS.

Rivedi le tue risorse:

  • Assicurati che le risorse (ad esempio, immagini, script) vengano caricate tramite HTTPS.
  • Riconfigura i login social e il CDN per HTTPS, se necessario.
  • Risolvi eventuali avvisi nella console del browser riguardanti risorse non sicure.

Discourse abilita automaticamente force_https dopo una ricompilazione con un certificato HTTPS valido.

Come funziona?

Il modello utilizza GitHub - acmesh-official/acme.sh: A pure Unix shell script ACME client for SSL / TLS certificate automation · GitHub che è

Lo script shell più semplice per il client di certificati gratuiti di Let’s Encrypt

Semplice e potente, ti bastano 3 minuti per imparare.

Scritto interamente in bash, senza dipendenze da Python, acme-tiny o il client ufficiale di Let’s Encrypt. Solo uno script per emettere e rinnovare automaticamente i tuoi certificati.

Probabilmente è lo script shell più piccolo, semplice e intelligente per emettere e rinnovare automaticamente i certificati gratuiti da Let’s Encrypt.

web.letsencrypt.ssl.template.yml aggiunge uno script di avvio al tuo contenitore che

  1. Avvia un nginx leggero per servire le sfide ACME sulla porta 80 prima che il nginx principale sia attivo.
  2. Emette sia un certificato RSA (4096-bit) che un certificato ECDSA (ec-256) di Let’s Encrypt utilizzando la modalità webroot con /var/www/discourse/public come directory.
  3. Installa i certificati nella directory /shared/ssl/ che nginx si aspetta. Allo stesso tempo, impostando un lavoro cron per il rinnovo automatico dei certificati. Questo rinnoverà automaticamente i tuoi certificati. Non succede nulla se i certificati non sono scaduti. Se un certificato scade, riceverai un’email da Let’s Encrypt all’indirizzo email fornito durante la configurazione.
  4. Imposta force_https su true se vengono ottenuti certificati validi.

Risoluzione dei problemi

Controllo dei log

Se HTTPS non funziona, controlla i log per errori SSL o Let’s Encrypt con:

./launcher logs app

Verifica dei file di certificazione

Assicurati che i file del certificato e della chiave siano presenti con:

ls -l /var/discourse/shared/standalone/ssl

Dovresti vedere file come:

  • tuodominio.com.cer (RSA)
  • tuodominio.com.key (RSA)
  • tuodominio.com_ecc.cer (ECDSA)
  • tuodominio.com_ecc.key (ECDSA)

Rinnovo manuale dei certificati

Se il rinnovo automatico fallisce, puoi riemettere manualmente i tuoi certificati:

./launcher enter app
sv stop nginx
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf
LE_WORKING_DIR=/shared/letsencrypt DEBUG=1 /shared/letsencrypt/acme.sh --issue -d example.com -k 4096 -w /var/www/discourse/public
LE_WORKING_DIR=/shared/letsencrypt /shared/letsencrypt/acme.sh --installcert -d example.com --fullchainpath /shared/ssl/example.com.cer --keypath /shared/ssl/example.com.key --reloadcmd "sv reload nginx"
LE_WORKING_DIR=/shared/letsencrypt DEBUG=1 /shared/letsencrypt/acme.sh --issue -d example.com --keylength ec-256 -w /var/www/discourse/public
LE_WORKING_DIR=/shared/letsencrypt /shared/letsencrypt/acme.sh --installcert --ecc -d example.com --fullchainpath /shared/ssl/example.com_ecc.cer --keypath /shared/ssl/example.com_ecc.key --reloadcmd "sv reload nginx"
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf -s stop

Ricompilazione con certificati puliti

Rimuovi i vecchi file di certificato e ricompila per ricominciare da capo:

rm -rf /var/discourse/shared/standalone/ssl
rm -rf /var/discourse/shared/standalone/letsencrypt
./launcher rebuild app

Limitazioni

I certificati di Let’s Encrypt convalidano solo il dominio e la crittografia. Non confermano la proprietà o l’identità, il che potrebbe essere segnalato in alcuni browser. Per ulteriori dettagli, fai riferimento alla community di Let’s Encrypt.

143 Mi Piace
Setting up Let's Encrypt for multisite
How should I enable letsencrypt while discourse is beside other websites
Cant setting SLL (Let's Encrypt) for Discourse
Add to homescreen banner on Android
How to Set Up SSL in Discourse
Setting up SSL with my domain name and Discourse instance
Issue installing on subdomain
Completely automated SSL certificate generation
German 1&1-hosting user experience?
Problem with my SSL certificate
Replacement for whitelist-iframe
Site throws a blank screen after trying to enable LetsEncrypt
Missing file(discourse.conf) when launching after lets encrypt update?
Missing file(discourse.conf) when launching after lets encrypt update?
My discourse has either been hacked or catfished?
Discourse has stopped opening
Using a certificate when Discourse is installed behind a reverse proxy
Can discourse be installed in private mode
My Forum Is showing "Privacy Error" after upgrading SSL certificate
Using a certificate when Discourse is installed behind a reverse proxy
Why my forum not pop-up "Add to Home screen"(PWA) automatically?
Why my forum not pop-up "Add to Home screen"(PWA) automatically?
HTTPS : issue while trying to set up SSL certification
HTTPS : issue while trying to set up SSL certification
SSL received a record that exceeded the maximum permissible length
Discourse site loads via IP but via domain only header
Why is the Apple Touch Icon loaded via HTTP instead of HTTPS?
Defaultish app won't rebuild
Why is the Apple Touch Icon loaded via HTTP instead of HTTPS?
Why is the Apple Touch Icon loaded via HTTP instead of HTTPS?
Defaultish app won't rebuild
Unable to connect Discourse and WordPress
I have a very difficult problem installing ssl - please help
Not able to access site after letsencrypt cert expiry and rebuild due to IPV6
Cannot connect to IP address and no errors in log
Http logo urls after enabling LetsEncrypt
How to install SSL certificate in Discourse
White blank page on mobile app
Cloud installation not working
My forum goes offline after removing https
Trying to use Let's Encrypt + Cloudflare
New user invite links only give ERR_SSL_PROTOCOL_ERROR
[DigitalOcean] hostname having "www" in A records showing blank page
Error at LetsEncrypt validation
Migrate a phpBB3 forum to Discourse
Set Up Let's Encrypt with Second Domain for Existing Discourse Install
Not starting up after rebuild
Port 443 of computer does not appear to be accessible
Make auto-linked URLs use HTTPS
Unable to change domain name
LetsEncrypt certificate not renewing
How to deny request from unauthorized domain pointing to my IP address?
No login is possible after recovery a Discourse Backup on a new server
Letsencrypt issued on every build?
My Discourse is Down. Certificate Issue?
Setup Let’s Encrypt + non-www > www
No connection accepted on http / https after fresh installation on Ubuntu 22.04 LTS
SSL certificate expired and after that - Error 404 Not Found
SSL didn't renew automatically and I can't manually renew it
443 address already in use? Letencrypt
Set up Let’s Encrypt with multiple domains / redirects
Using Discourse with Cloudflare: Best Practices
./launcher rebuild app error bootstrap failed with exit code 125
Set up Let’s Encrypt with multiple domains / redirects
Uncaught ReferenceError: Discourse is not defined due to Cloudflare Rocket Loader
Let's Encrypt SSL Certificate Not Renewing
Uploads paths have 80 port but protocol is https
Bootstrap error during Discourse install: ENOENT - /etc/runit/1.d/letsencrypt
How to install Discourse in the AWS EC2 Instances(Ubuntu Server LTS)?
Question about the email configuration
Discourse-saml: There was an error authorizing your account
Problem in installing Let's Encrypt SSL for www and non-www
Email not sending out after installation. I need help please
Discourse not starting up: nginx: unable to open supervise/ok: file does not exist
Failed to bootstrap: Failure with receiving network data
Error when installing ssl Let's Encrypt
How to adjust dependencies for https?
Clicking links is stuck in click tracking, shows ERR_FAILED
Minimum needed to get LetsEncrypt working on a GCE instance
Can we install discourse in another container distro?
Problem with my SSL certificate
Cant setting SLL (Let's Encrypt) for Discourse
[PAID] setup ssl - Let's encrypt
Error after moving from HTTP to HTTPS
How to renew Let's Encrypt?
ServiceWorker script evaluation failed due to HTTP (not HTTPS)
Defaultish app won't rebuild
Too many redirects after enabling https