免费https ssl证书 Ubuntu

Let's Encrypt简介

Let's Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等组织人员发起,主要的目的也是为了推进网站从HTTP向HTTPS过度的进程,目前已经有越来越多的商家加入和赞助支持。

Let's Encrypt免费SSL证书的出现,也会对传统提供付费SSL证书服务的商家有不小的打击。到目前为止,Let's Encrypt获得IdenTrust交叉签名,这就是说可以应用且支持包括FireFox、Chrome在内的主流浏览器的兼容和支持,虽然目前是公测阶段,但是也有不少的用户在自有网站项目中正式使用起来。

Let's Encrypt 的最大贡献是它的 ACME 协议,第一份全自动服务器身份验证协议,以及配套的基础设施和客户端。这是为了解决一直以来 HTTPS TLS X.509 PKI 信任模型,即证书权威(Certificate Authority, CA)模型缺陷的一个起步。在客户端-服务器数据传输中,公私钥加密使得公钥可以明文传输而依然保密数据,但公钥本身是否属于服务器,或公钥与服务器是否同属一个身份,是无法简单验证的。证书权威模型通过引入事先信任的第三方,由第三方去验证这一点,并通过在服务器公钥上签名的方式来认证服务器。第三方的公钥则在事先就约定并离线准备好,以备访问时验证签名之用。这个第三方就称为证书权威,简称CA。相应的,CA验证过的公钥被称为证书。问题是,如果服务器私钥泄露,CA无法离线使对应的证书无效化,只能另外发布无效记录供客户端查询。也就是说,在私钥泄露到CA发布无效记录的窗口内,中间人可以肆意监控服-客之间的传输。如果中间人设法屏蔽了客户端对无效记录的访问,那么直到证书过期,中间人都可以进行监控。而由于当前CA验证和签发证书大多手动,证书有效期往往在一年到三年。Let's Encrypt 签发的证书有效期只有90天,甚至希望缩短到60天。有效期越短,泄密后可供监控的窗口就越短。

前提:

假定你已经用nginx搭建好网站

怎么搭建nginx的,这里我就不多说了

安装Certbot

Certbot是维护Let's Encrypt的Package。

添加package repository

sudo add-apt-repository ppa:certbot/certbot

直接回车,添加完毕后,更新apt源数据:

sudo apt-get update

然后安装Certbot的Nginx package:

sudo apt-get install python-certbot-nginx

签发ssl证书

现在使用Let's Encrypt签发ssl证书:

sudo certbot --nginx -d your-domian.com -d www.your-domain.com

注意这里的 your-domain.com 换成你自己的域名,如果你第一次运行certbot的话,会让你输入邮箱,还要接受Let's Encrypt的协议,最后会让你选择是否重定向http到https:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.

选2,重定向即可。

最后可以看到生成的证书的位置:


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/oyty.me/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/oyty.me/privkey.pem
   Your cert will expire on 2018-09-24. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

 这个时候,ssl证书已经自动签发完毕了,你可以访问网站,发现已经是https的了。

查看我之前的nginx配置文件

server {
      # listen       80;
       listen         443 ssl;
	server_name www.you.com;
	ssl_certificate      /etc/letsencrypt/live/www.you.org/fullchain.pem;
	ssl_certificate_key   /etc/letsencrypt/live/www.you.org/privkey.pem;
	ssl_session_cache    shared:SSL:1m;
	ssl_session_timeout  5m;
	ssl_ciphers  HIGH:!aNULL:!MD5;
	ssl_prefer_server_ciphers  on;
    #以上代码才是重点

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
       
        location / {
            root   /opt/www;
            index index.php index.html index.htm;
	    if (!-e $request_filename) {
		rewrite  ^(.*)$  /index.php?s=$1  last;
		break;
	    }
        }
	location ~ \.php$ {
        	fastcgi_pass   127.0.0.1:9000;
        	fastcgi_index  index.php;
        	fastcgi_param  SCRIPT_FILENAME  /opt/www$fastcgi_script_name;

		fastcgi_connect_timeout 300;
		fastcgi_send_timeout 300;
		fastcgi_read_timeout 300;
		fastcgi_buffer_size 64k;
		fastcgi_buffers 4 64k;
		include        fastcgi_params;
	}        

    }

ssl证书文件自动集成了,如果没有你也可以根据生成的证书地址自己配置。

自动更新证书

因为 Let's Encrypt 签发的 SSL 证书有效期只有 90 天,所有在过期之前,我们需要自动更新 SSL 证书,而如果你使用最新的 certbot 的话,Let's Encrypt 会帮你添加自动更新的脚本到 /etc/cron.d 里,你只需要去检测一下这个命令是否生效就OK!

sudo certbot renew --dry-run

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值