Let's Encrypt 实践

第一步

下载certbot:https://certbot.eff.org/#centosrhel6-nginx

sudo yum install epel-release
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

第二步

mkdir /var/www/idaigouyi
./certbot-auto certonly --webroot -w /var/www/idaigouyi -d idaigouyi.com -d www.idaigouyi.com

第三步

mkdir /etc/nginx/ssl
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

第四步

cd /etc/letsencrypt/live/idaigouyi.com
wget https://letsencrypt.org/certs/isrgrootx1.pem
mv isrgrootx1.pem root.pem
cat root.pem chain.pem > root_ca_cert_plus_intermediates

第五步

Mozilla SSL Configuration Generator生成默认配置,并修改关键部分:

  • ssl_certificate
  • ssl_certificate_key
  • ssl_dhparam
  • ssl_trusted_certificate
  • resolver
server {  
    listen 80 default_server;
    listen [::]:80 default_server;

    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    return 301 https://$host$request_uri;
}
server {  
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /etc/letsencrypt/live/idaigouyi.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/idaigouyi.com/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
    ssl_dhparam /etc/nginx/ssl/dhparam.pem;

    # intermediate configuration. tweak to your needs.
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    # OCSP Stapling ---
    # fetch OCSP records from URL in ssl_certificate and cache them
    ssl_stapling on;
    ssl_stapling_verify on;

    ## verify chain of trust of OCSP response using Root CA and Intermediate certs
    ssl_trusted_certificate /etc/letsencrypt/live/idaigouyi.com/root_ca_cert_plus_intermediates;

    resolver 10.143.23.18 10.143.23.29;

    ....
}

第六步

重启nginx,这时候你的站点应该默认强制使用了 HTTPS,并且浏览器地址栏左边会有绿色的小锁:

service nginx stop
service nginx start

第七步

用专业在线工具测试你的服务器 SSL 安全性,Qualys SSL Labs 提供了全面的 SSL 安全性测试,填写你的网站域名,给自己的 HTTPS 配置打个分。我的网站打分:https://www.ssllabs.com/ssltest/analyze.html?viaform=on&d=idaigouyi.com

第八步

自动化定期更新证书,Let's Encrypt 证书有效期是3个月,我们可以通过 certbot 来自动化续期。

./certbot-auto renew --dry-run
./certbot-auto renew --quiet

--dry-run参数用于测试自动化更新是否可行,会不会报错。如果没有报错的话,就可以将./certbot-auto renew命令加到crontab里定期进行更新。

results matching ""

    No results matching ""