为nginx配置Let’s Encrypt免费的SSL安全证书

2016年10月6日 标签:, 0 条评论

以下为命令片段,仅供个人收藏,懂的人都能懂。

cd /usr/local/sbin
sudo wget https://dl.eff.org/certbot-auto

sudo chmod a+x /usr/local/sbin/certbot-auto

nano /etc/nginx/sites-available/example.com

location ~ /.well-known {
allow all;
}

certbot-auto certonly -a webroot –webroot-path=/usr/html/domains/example.com -d example.com -d www.example.com

sudo ls -l /etc/letsencrypt/live/example.com

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

nano /etc/nginx/sites-available/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;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}

sudo crontab -e

30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log
35 2 * * 1 /etc/init.d/nginx reload

最终验证下,直接是A级别了:https://www.ssllabs.com/ssltest/analyze.html?d=example.com

上一篇: | 下一篇:

Comments

  1. 还没有任何评论,你来说两句吧

发表评论

  • 发表评论