欢迎您光临深圳塔灯网络科技有限公司!
电话图标 余先生:13699882642

网站百科

为您解码网站建设的点点滴滴

certbot配置网站SSL安全证书

发表日期:2018-12 文章编辑:小灯 浏览次数:4062

总觉得写个文章应该有个起承转合是吧,那就讲一下起因吧,老夫发现postman不能测试接口了。。。好吧我选择了最麻烦的一个解决方法,也算是闲的蛋疼。

正文

第一步当然是下载安装

 $ wgethttps://dl.eff.org/certbot-auto$ chmod a+x ./certbot-auto$ ./certbot-auto

这个小工具会自动下载并安装相关依赖和 Python 包。稍等一下就完成了。

第二部生成证书

生成证书过程中需要鉴权。有多种方式,比如webroot、standalone、apache、nginx、manual等。我使用过前两种。 这两种中,简单一点的是standalone。不过,这种方式需要把现有的 WebServer 停掉,因为这种方式下 certbot 需要占用 80 端口。

# ./certbot-auto certonly --text --agree-tos --email webmaster@example.com --standalone -d example.com -d www.example.com -d service.example.com 

-d参数指定域名,可多个。一般第一个是主域名。

webroot方式稍微繁琐一些,但好处是不需要关停现有的 WebServer 。此方法需要在域名对应的根目录下新建.well-known目录并写入若干文件供验证服务访问。 因此需要配置 WebServer 允许外部访问http://example.com/.well-known路径。配置方法请参考相应 WebServer 的文档。Nginx 的默认配置应该不用修改,Apache 就不知道了。 另外,不同的域名的根路径可能不同,下面的例子中可以看到为不同的域名指定不同的根路径。

# ./certbot-auto certonly --text --agree-tos --email webmaster@excample.com --webroot -w /var/www/example -d example.com -d www.example.com -w /var/service/example -d service.ulefa.com 

无论使用那种方式,运行以上命令后都会在/etc/letsencrypt生成一堆东西,包括证书。

第三步修改Nginx 配置以提供 HTTPS 服务

打开 Nginx 的配置文件(默认为:/etc/nginx/nginx.conf),在需要提供 HTTPS 的server下新增以下三行,并把listen 80;删掉:

ssl_certificate /etc/letsencrypt/live/api.bqtabc.adflash.cn/fullchain.pem;ssl_certificate_key/etc/letsencrypt/live/api.bqtabc.adflash.cn/privkey.pem;ssl_session_timeout 5m;ssl_protocols SSLv2 SSLv3 TLSv1;ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;ssl_prefer_server_ciphers on; 

新增以下server使所有 HTTP 请求都跳转至 HTTPS :

server {listen80;server_name example.com www.example.com service.example.com;return301 https://$host$request_uri;} 

最后定期 renew

Let's Encrypt 的证书有效期为 90 天,所以需要在到期前 renew 一下证书。 使用以下命令即可。

# ./certbot-auto renew --text --agree-tos --email webmaster@excample.com --webroot -w /var/www/example -d example.com -d www.example.com -w /var/service/example -d service.ulefa.com 

或者直接运行以下命令,此时 certbot 会使用默认参数(此例为:/etc/letsencrypt/renewal/example.com.conf):

# ./certbot-auto renew 

又或者在crontab里加入定时任务,每隔 80 天的凌晨 4 点执行一次 renew:

04 */80 * * /path/to/certbot-auto renew &>> /dev/null 

本页内容由塔灯网络科技有限公司通过网络收集编辑所得,所有资料仅供用户学习参考,本站不拥有所有权,如您认为本网页中由涉嫌抄袭的内容,请及时与我们联系,并提供相关证据,工作人员会在5工作日内联系您,一经查实,本站立刻删除侵权内容。本文链接:https://dengtar.com/20539.html
相关开发语言
 八年  行业经验

多一份参考,总有益处

联系深圳网站公司塔灯网络,免费获得网站建设方案及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:余经理:13699882642

Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.