教程:Ubuntu / DEBIAN 和Nginx下,安装、设置Let’s Encrypt SSL

教程:Ubuntu / DEBIAN 和Nginx下,安装、设置Let’s Encrypt SSL

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

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

适用于Ubuntu / DEBIAN,本文在Ubuntu 14.04下成功安装。 举例:域名为zhujiwiki.com ,ip为111.111.111.111

SSH下: 1、安装git 和 bc sudo apt-get install git bc

2、拷贝le源码 cd /tmp/ git clone https://github.com/Neilpang/le.git

3、安装le.sh cd le sudo ./le.sh install

然后 source ~/.bashrc

4、测试安装是否成功 sudo -s le

使用le过程中,必须使用命令sudo -s

5、创建/.well-known/acme-challenge/目录 mkdir -p /var/www/html/.well-known/acme-challenge/ chown -R www-data:www-data /var/www/html/.well-known/acme-challenge/ chmod -R 0444 /var/www/html/.well-known/acme-challenge/

6、创建存储SS证书的目录 mkdir -p /etc/nginx/ssl/zhujiwiki.com/

然后 openssl dhparam -out dhparams.pem 4096

7、签发zhujiwiki.com 和www.zhujiwiki.com的ssl证书 le issue /var/www/html zhujiwiki.com www.zhujiwiki.com

默认为2048 bit,也可以签发4096,如下命令: le issue /var/www/html zhujiwiki.com www.zhujiwiki.com 4096

签发命令如下: le issue /DocumentRootPath/ example.com le issue /DocumentRootPath/ example.com www.foo.com,bar.com le issue /DocumentRootPath/ example.com 2048

8、在Nginx上配置TLS/SSL vi /etc/nginx/sites-available/default 按i进入编辑模式,粘贴如下内容:

## START: SSL/HTTPS zhujiwiki.com ### server { #------- Start SSL config ----## listen 111.111.111.111:443; server_name zhujiwiki.com; ssl on; ssl_certificate /etc/nginx/ssl/theos.in/zhujiwiki.com.cer; ssl_certificate_key /etc/nginx/ssl/theos.in/zhujiwiki.com.key; ssl_session_timeout 30m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS; ssl_session_cache shared:SSL:10m; ssl_dhparam /etc/nginx/ssl/zhujiwiki.com/dhparams.pem; ssl_prefer_server_ciphers on; ## Improves TTFB by using a smaller SSL buffer than the nginx default ssl_buffer_size 8k; ## Enables OCSP stapling ssl_stapling on; resolver 8.8.8.8; ssl_stapling_verify on; ## Send header to tell the browser to prefer https to http traffic add_header Strict-Transport-Security max-age=31536000; ## SSL logs ## access_log /var/log/nginx/zhujiwiki.com/ssl_access.log; error_log /var/log/nginx/zhujiwiki.com/ssl_error.log; #-------- END SSL config -------## # Add rest of your config below like document path and more ## } ## END SSL zhujiwiki.com ######

按Esc键退出编辑模式,然后按着shift并同时连按2次z,即回到shell界面。

9、在Nginx上安装已签发的证书 le installcert theos.in /etc/nginx/ssl/theos.in/theos.in.cer /etc/nginx/ssl/theos.in/theos.in.key /etc/nginx/ssl/theos.in/ca.cer ‘service nginx reload’

为避免出现链接问题,输入如下命令: cd /etc/nginx/ssl/theos.in/ cat theos.in.cer ca.cer > foo mv foo theos.in.cer service nginx reload

10、使用443端口 ufw allow proto tcp from any to 111.111.111.111 port 443

在浏览器上测试:https://zhujiwiki.com/,或者使用SSL labs测试

11、le免费证书有效期为90天,所有需要更新证书,命令如下: le renew zhujiwiki.com

添加自动更新,就不用在担心证书过期啦。 crontab -e

按i进入编辑模式 0 0 * * * LE_WORKING_DIR=”/root/.le” “/root/.le”/le.sh cron > /dev/null 按Esc键退出编辑模式,然后按着shift并同时连按2次z,即回到shell界面。

推荐站内搜索:云服务器官网、国内虚拟主机、vps动态ip、本地ip、游戏服务器防御、备案域名租用、国外空间服务商、服务器、虚拟主机、注册 域名、