活到老学到老  

记录遇到问题的点点滴滴。

在Nginx上https部署 Let's Encrypt 证书

8年前发布  · 2163 次阅读

Linux基金会宣布它将托管Let's Encrypt项目和互联网安全研究组(ISRG)。Let’s Encrypt CA项目由Mozilla、思科、Akamai、IdenTrust和EFF等组织发起,向网站自动签发和管理免费证书,加速将Web从HTTP过渡到HTTPS。ISRG则是开发Let’s Encrypt CA的非营利组织。

今天我来教大家在Nginx上部署Let's Encrypt证书 下载Let's Encrypt客户端

首先我们要安装git

Ubuntu

apt-get update
apt-get -y install git

CentOS

yum -y install git

然后,检出Let's Encrypt的客户端源码

$ git clone https://github.com/letsencrypt/letsencrypt
$ cd letsencrypt

这样,我们就成功的下载了Let's Encrypt的客户端签发证书 首先,要先关掉我们的Nginx。使用命令关闭Nginx,不同环境方法不同,请参考你自己的环境配置说明 如果不确定,你可以使用

netstat -na | grep ':80.*LISTEN'

命令来检测,当返回值为空时,就说明没有程序在监听80端口 接下来,进入Let's Encrypt目录

运行Standalone插件

./letsencrypt-auto certonly --standalone --debug

letsencrypt报错解决 ./letsencrypt-auto: line 460: virtualenv: command not found

注意:Let's Encrypt需要超级用户权限来运行。如果你不是Root用户,可以使用sudo来运行 输入信息

在你运行插件后,Let's Encrypt会进入初始化阶段,这时,你要输入一些信息,用于生成证书这个是输入邮箱,你可以填入自己的邮箱,这里填you@example.com这个是让你看Let's Encrypt的TOS。无视,直接Agree接下来,就要输入你自己的域名了 这里输入example.com 和www.example.com 多域名用空格隔开 输入完按OK 如果你看到这样的文字,就说明生成了

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/example.com/fullchain.pem. Your
   cert will expire on 2016-03-19. To obtain a new version of the
   certificate in the future, simply run Let's Encrypt again.
- Your account credentials have been saved in your Let's Encrypt
   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 Let's
   Encrypt so making regular backups of this folder is ideal.
- If like Let's Encrypt, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

这段文字提示了证书的存放位置和过期日期 我的存放位置是 /etc/letsencrypt/live/example.com/fullchain.pem 在2016年3月19日过期 我们配置Nginx证书时的证书文件和密钥文件都在那个目录下。其中fullchain.pem包含了网站证书和根证书链 配置Nginx 修改我们的虚拟主机配置文件,在listen后面把80改成443,并加SSL,然后在下面加入我们的证书和密钥地址。

        listen 443 ssl;
        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_ciphers AES256+EECDH:AES256+EDH:!aNULL;

然后保存,退出,重启Nginx即可!