Comment activer un site en HTTPS sur un serveur déployé par Octopuce en utilisant Let’s Encrypt, autorité de certification gratuite ?
C’est facile, et vos certificats seront renouvelés automatiquement tous les 2 mois par l’intérmédiaire d’un script de renouvellement
Vous pourrez utiliser votre certificat dans d’autres d’applications (XMPP, Node, etc.).
Si vous ne voulez que le certificat, la seule commande à connaître est :
cert mondomaine.tld www.mondomaine.tld
Dans ce cas, il est nécessaire qu’un serveur web « standard » (apache2, nginx) soit installé sur le serveur : c’est nécessaire pour l’obtention du certificat.
Prérequis:
- Disposer d’un compte shell avec droit sudo
- Disposer d’une IP publique
- Être sur un serveur OCTOPUCE et avoir demandé l’activation de letsencrypt
Vous trouverez plus loin :
Et maintenant, aux commandes, voici le déroulé en script shell.
Attention à bien remplir votre nom de domaine et le serveur web :
# Remplacer avec votre domaine DOMAINE="example.net" # Quel serveur (apache ou nginx) est utilisé pour ce domaine ADDRESSE_IP=$(dig +short A $DOMAINE) # Identifier quel est le serveur web utiliser netstat -lntpt|egrep "(80|443)" # Remplacer avec votre serveur web, utilisons "nginx", sinon "apache2" SERVER="nginx" # Demander le nouveau certificat avec la fonction cert cert www.$DOMAINE $DOMAINE # Le certificat sera dans /etc/letsencrypt/live/www.$DOMAINE # Chercher si un vhost existe (ou pas) grep -RinH $DOMAINE /etc/$SERVER/sites-enabled # Ajouter / modifier le vhost vim /etc/$SERVER/sites-available/$DOMAINE.conf # Faire le lien symbolique dans enabled et reload cd /etc/$SERVER/sites-enabled/ ln -s ../sites-available/$DOMAINE.conf # Tester la conf avec nginx -t ou apachectl -t # Recharger la configuration serveur service "$SERVER" reload # Vérifier que ça marche (notamment le SSL) wget -S -O /dev/null https://www.$DOMAINE # Vérifier sur ssllab echo "Aller sur https://www.ssllabs.com/ssltest/analyze.html?d=www.$DOMAINE&latest"
Exemples de vhost
Apache2
ServerName www.DOMAINE
ServerAlias DOMAINE
DocumentRoot "/var/www/alternc/u/user/www/DOMAINE/public/"
# Add this for AlternC
# AssignUserId #2001 #2001
# SetEnv LOGIN "2001-user"
# Replace with your port 80 configuration
<Directory "/var/www/alternc/u/user/www/DOMAINE/public/">
php_admin_value open_basedir "/var/www/alternc/u/user/:/usr/share/php/"
php_admin_value upload_tmp_dir /var/www/alternc/u/user/tmp
php_admin_value sendmail_path '/usr/lib/alternc/sendmail "user@server.octopuce.fr" '
php_admin_flag mail.add_x_header on
AllowOverride AuthConfig FileInfo Limit Options Indexes
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/DOMAINE/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/DOMAINE/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/DOMAINE/chain.pem
Nginx
server {
listen 91.194.60.XXX ssl; ## Replace with your ipv4 or *
listen 2001:67c:288::XXX/64:443 ssl; ## Replace with your ipv6
root /var/www/DOMAINE;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name www.DOMAINE DOMAINE ;
ssl on;
location / {
# Use your current 80 proxy / fcgi, this is only an example
proxy_pass http://localhost;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
keepalive_timeout 10;
ssl_certificate /etc/letsencrypt/live/DOMAINE/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/DOMAINE/privkey.pem;
}
cert ()
{
[ -e "/usr/bin/letsencrypt" ] || {
echo "Executable 'letsencrypt' not found";
return 1
};
local LIST="$@";
[ -z "$LIST" ] && {
echo "Please provide a list of domains: domain.com mail.domain.com etc.";
return 1
};
local DOM_PART="";
for f in $@;
do
DOM_PART+=" -d $f";
done;
/usr/bin/letsencrypt certonly --webroot --agree-tos -w /var/www/letsencrypt/ --email domaines@octopuce.fr --expand $DOM_PART
}