分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

免费 Https 证书(Let's Encrypt)申请与配置

发布时间:2023-09-06 01:30责任编辑:顾先生关键词:配置

之前要申请免费的 https 证书操作步骤相当麻烦,今天看到有人在讨论,就搜索了一下。发现现在申请步骤简单多了。

1. 下载 certbot

git clone https://github.com/certbot/certbotcd certbot./certbot-auto --help

解压打开执行就会有相关提示

2. 生成免费证书

./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-challenge 是否存在来确定你对网站的所属权

比如:我的域名是 note.crazy4code.com 那我就得保证域名下面的 .well-known/acme-challenge/ 目录是可访问的         可以操作chmod 777 -R /网站根目录/.well-known/acme-challenge

如果返回正常就确认了你对这个网站的所有权,就能顺利生成,完成后这个目录会被清空

3. 获取证书

如果上面的步骤正常 shell 脚本会展示如下信息:

- Congratulations! Your certificate and chain have been saved at/etc/letsencrypt/live/网站域名/fullchain.pem...

4. 生成 dhparams

使用 openssl 工具生成 dhparams

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

5. 配置 Nginx

打开 nginx server 配置文件加入如下设置:

listen 443ssl 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 服务就可以了

6. 强制跳转 https

https 默认是监听 443 端口的,没开启 https 访问的话一般默认是 80 端口。如果你确定网站 80 端口上的站点都支持 https 的话加入下面的配件可以自动重定向到 https

server { ???listen 80; ???server_name your.domain.com; ???return 301 https://$server_name$request_uri;}

7. 证书更新

免费证书只有 90 天的有效期,到时需要手动更新 renew。刚好 Let’s encrypt 旗下还有一个 Let’s monitor 免费服务,注册账号添加需要监控的域名,系统会在证书马上到期时发出提醒邮件,非常方便。收到邮件后去后台执行 renew 即可,如果提示成功就表示 renew 成功

./certbot-auto renew



实际操作:

[root@test html]# chmod 777 -R .well-known/

./certbot-auto certonly --webroot --agree-tos -v -t --email zhaoweifeng@hl***ang.cn -w /var/www/html -d test.b****wkd.com


IMPORTANT NOTES:

- Congratulations! Your certificate and chain have been saved at:
??/etc/letsencrypt/live/test.bjy***d.com/fullchain.pem
??Your key file has been saved at:
??/etc/letsencrypt/live/test.bj***d.com/privkey.pem
??Your cert will expire on 2018-03-14. To obtain a new or tweaked
??version of this certificate in the future, simply run certbot-auto
??again. To non-interactively renew *all* of your certificates, run
??"certbot-auto renew"




免费 Https 证书(Let's Encrypt)申请与配置

原文地址:http://www.cnblogs.com/weifeng1463/p/8039135.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved