Установка certbot
Если вы используете Debian Buster или Debian testing/Sid, вы можете просто установить certbot командами:
Code Block |
---|
|
sudo apt-get update
sudo apt-get install certbot |
Если вы используете Debian Stretch, рекомендуется устанавливать certbot из пакетов репозитория Debian backports. Сначала нужно подключить репозиторий Debian backports. Для этого нужно добавить в файл /etc/apt/sources.list строку:
Code Block |
---|
|
deb http://deb.debian.org/debian stretch-backports main |
После этого установить certbot из репозитория Debian backports:
Code Block |
---|
|
sudo apt-get update
sudo apt-get install certbot -t stretch-backports |
Создание сертификата
Останавливаем Apache:
Code Block |
---|
|
sudo service apache2 stop |
Останавливать Apache на время создания/продления сертификата нужно потому, что мы запускаем certbot в режиме standalone. В этом режиме он, для подтверждения владения доменом, сам начинает работать как вебсервер, и Apache нужно остановить, чтобы они не конфликтовали.
Запускаем certbot (вместо "YOUR_DOMAIN" нужно ввести ваш домен):
Code Block |
---|
|
sudo certbot certonly --standalone -d YOUR_DOMAIN |
Вас спросят email:
Code Block |
---|
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): |
Попросят принять Terms of Service:
Code Block |
---|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: |
Попросят поделиться email'ом с EFF (здесь можно отказаться):
Code Block |
---|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: |
Пошёл процесс получения сертификата:
Code Block |
---|
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for YOUR_DOMAIN
Waiting for verification...
Cleaning up challenges |
Успех:
Code Block |
---|
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem
Your cert will expire on 2020-07-12. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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 |
Теперь нужно заменить самоподписанный сертификат на новый от Let's Encrypt.
Заменяем в файле /etc/apache2/sites-enabled/abills_httpd.conf строки
Code Block |
---|
SSLCertificateFile /usr/abills/Certs/server.crt
SSLCertificateKeyFile /usr/abills/Certs/server.key |
на
Code Block |
---|
SSLCertificateFile /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem |
где YOUR_DOMAIN - ваш домен.
Запускаем Apache:
Code Block |
---|
sudo service apache2 start |
Теперь можно зайти на сайт с браузера, и проверить, что браузер считает этот сертификат валидным.
Настройка автопродления сертификата
certbot сам настроил автопродление на предыдущем шаге (прописав себя в cron или в systemd timers). Нужно только настроить хуки, чтобы перед запуском продления apache останавливался, а после - запускался:
Code Block |
---|
|
sudo sh -c 'printf "#!/bin/sh\nservice apache2 stop\n" > /etc/letsencrypt/renewal-hooks/pre/apache.sh'
sudo sh -c 'printf "#!/bin/sh\nservice apache2 start\n" > /etc/letsencrypt/renewal-hooks/post/apache.sh'
sudo chmod 755 /etc/letsencrypt/renewal-hooks/pre/apache.sh
sudo chmod 755 /etc/letsencrypt/renewal-hooks/post/apache.sh |