Опыт установки сертификата Let's Encrypt на Ubuntu и nginx
Let’s Encrypt — некоммерческий центр сертификации, предоставляющий бесплатные криптографические сертификаты X.509 для TLS шифрования (HTTPS). Процесс выдачи сертификатов полностью автоматизирован с помощью клиента Certbot. Сертификаты выдаются на 90 дней, однако процесс выпуска новых сертификатов также автоматизирован.
Я бы назвал процесс установки сертификата с использованием certbot супердружелюбным, никакой правки конфигурационных файлов вручную не требуется.
Исходные данные:
- os: ubuntu 16.04
- web-server: nginx
Процесс установки
На главной странице проекта Certbot выбираем операционную систему и веб-сервер,
и получаем инструкцию по установке:
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx
У Certbot есть плагины, в том числе для Nginx, которые поддерживается на многих платформах и автоматизирует получение и установку сертификатов:
$ sudo certbot --nginx
И тут начинается магия: запускается интерактивный мастер установки сертификата. Он спрашивает, мы отвечаем.
- Адрес для отправки электронных писем.
- Согласие с условиями использования
- Согласие на получение писем от разработчиков Certbot и Electronic Frontier Foundation (учредитель-партнер Let’s Encrypt)
- На какой домен необходимо получить сертификат?
- Нужен редирект с HTTP на HTTPS?
Собственно всё, можно идти проверять сертификат
tyapk@host:~$ sudo certbot --nginx
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): tyapk@tyapk.ru
-------------------------------------------------------------------------------
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-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: a
-------------------------------------------------------------------------------
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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: y
Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: xxxx.ru
2: www.xxxx.ru
3: xxx.icc.ru
4: tyapk.ru
5: www.tyapk.ru
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for xxxx.ru
Waiting for verification...
Cleaning up challenges
Deployed Certificate to VirtualHost /etc/nginx/sites-enabled/xxxx.conf for set(['www.xxxx.ru', 'xxxx.ru'])
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://xxxx.ru
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=xxxx.ru
-------------------------------------------------------------------------------
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/xxxx.ru/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/xxxx.ru/privkey.pem
Your cert will expire on 2018-03-24. 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"
- 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
Автоматическое обновление
Пакеты Certbot поставляются с заданием cron, которое автоматически обновит ваши сертификаты до истечения срока их действия. Вы можете протестировать автоматическое обновление сертификатов, выполнив следующую команду:
$ sudo certbot renew --dry-run
Более подробную информацию и варианты обновления можно найти в документации.
tyapk@host:~$ sudo certbot renew --dry-run
[sudo] пароль для tyapk:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/xxxx.ru.conf
-------------------------------------------------------------------------------
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
tls-sni-01 challenge for xxxx.ru
Waiting for verification...
Cleaning up challenges
-------------------------------------------------------------------------------
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/xxxx.ru/fullchain.pem
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/xxxx.ru/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
-------------------------------------------------------------------------------
IMPORTANT NOTES:
- 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.