|
|||||||
Настройка Nginx с Let's Encrypt на CentOS 7
Время создания: 13.07.2018 15:31
Текстовые метки: ssl nginx letsencrypt
Раздел: SSL
Запись: Velonski/mytetra-database/master/base/1517201886yoochp7xd3/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
Наверно, многие уже в курсе, что компания Let's Encrypt раздает бесплатные SSL-сертификаты на https://letsencrypt.org . Как же его получить и настроить на своем сервере под управлением CentOS 7 и Nginx? Введение
Шаг 1 — Установка клиента Letsencrypt
sudo yum -y install git bc
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
Шаг 2 — Получение сертификата
Установка сертификата SSL
cd /opt/letsencrypt ./letsencrypt-auto certonly -a webroot --webroot-path=/usr/share/nginx/html -d example.com -d www.example.com Примечание: запускаем приложение letsencrypt-auto без sudo
Output: IMPORTANT NOTES: - If you lose your account credentials, you can recover through e-mails sent to sammy@digitalocean.com - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2016-03-15. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - Your account credentials have been saved in your Let's Encrypt 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 Let's Encrypt so making regular backups of this folder is ideal. - If like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
Если вы получили ошибки, типа: Failed to connect to host for DVSNI challenge, настройте firewall вашего сервера, что бы TCP трафик проходил по портам 80 и 443.
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
server { # перенаправление с 80 порта, а также с www server_name example.com www.example.com listen 80; return 301 https://www.example.com$request_uri; } server { listen 443 ssl; server_name example.com www.example.com; # Указываем пути к сертификатам ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_dhparam /etc/ssl/certs/dhparam.pem; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA'; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; # позволяем серверу прикреплять OCSP-ответы, тем самым уменьшая время загрузки страниц у пользователей ssl_stapling on; ssl_stapling_verify on; add_header Strict-Transport-Security max-age=15768000; location ~ /.well-known { allow all; } # The rest of your server block root /usr/share/nginx/html; index index.html index.htm; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } }
sudo systemctl reload nginx Шаг 4 — Настройка автопродление
/opt/letsencrypt/letsencrypt-auto renew
Checking for new version... Requesting root privileges to run letsencrypt... /root/.local/share/letsencrypt/bin/letsencrypt renew Processing /etc/letsencrypt/renewal/example.com.conf The following certs are not due for renewal yet: /etc/letsencrypt/live/example.com/fullchain.pem (skipped) No renewals were attempted.
sudo crontab -e
30 2 * * 1 /opt/letsencrypt/letsencrypt-auto renew >> /var/log/le-renew.log 35 2 * * 1 /usr/bin/systemctl reload nginx
Шаг 5 — Обновление Let’s Encrypt (не обязательно)
cd /opt/letsencrypt sudo git pull
Источники
|
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|