原文:https://keelii.github.io/2016/06/12/free-https-cert-lets-encrypt-apply-install/nginx
以前要申请免费的 https 证书操做步骤至关麻烦,今天看到有人在讨论,就搜索了一下。发现如今申请步骤简单多了。git
git clone https://github.com/certbot/certbot cd certbot ./certbot-auto --help
解压打开执行就会有相关提示github
./certbot-auto certonly --webroot --agree-tos -v -t --email 邮箱地址 -w 网站根目录 -d 网站域名 ./certbot-auto certonly --webroot --agree-tos -v -t --email keeliizhou@gmail.com -w /path/to/your/web/root -d note.crazy4code.com
注意 这里 默认会自动生成 /__网站根目录__/.well-known/acme-challenge,而后 shell 脚本会对应的访问 __网站域名__/.well-known/acme-challengeweb
若是返回正常就确认了你对这个网站的全部权,就能顺利生成shell
若是上面的步骤正常 shell 脚本会展现以下信息:bash
- Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/网站域名/fullchain.pem ...
使用 openssl 工具生成 dhparamsapp
openssl dhparam -out /etc/ssl/certs/dhparams.pem 2048
打开 nginx server 配置文件加入以下设置:dom
listen 443 ssl on; ssl_certificate /etc/letsencrypt/live/网站域名/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/网站域名/privkey.pem; ssl_dhparam /etc/ssl/certs/dhparams.pem; ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5;
而后重启 nginx 服务就能够了工具
https 默认是监听 443 端口的,没开启 https 访问的话通常默认是 80 端口。若是你肯定网站 80 端口上的站点都支持 https 的话加入下面的配件能够自动重定向到 https网站
server { listen 80; server_name your.domain.com; return 301 https://$server_name$request_uri; }