CloudFlare最近推出了UniversalSSL功能,向所有CloudFlare用户(包括免费用户)提供SSL加密功能。不得不说,这绝对是一项造福人类的好事情,要知道,购买正式的SSL证书起码要支付每年400+美刀的费用,这也是为什么只有少数网站才会提供高大上的HTTPS服务的原因,CloudFlare此举无疑为未来互联网的全面加密时代吹响了号角。
        当然,这个博客没有任何必需要加密传输的内容,我只是实验一下,结果还是很不错的。大家可能注意到我博客右侧多出一个“加密链接”的按钮,通过这个按钮或者直接在浏览器中通过输入“https://www.thecodeway.com”来访问我这个博客的https版本。下图是CloudFlare提供的SSL加密的几种模式,可以看出其原理很简单,它并不是为每个网站提供一份加密证书,而是通过云服务器,将流经用户和服务器之间数据加密。

        我使用的是其中的Full SSL模式,也就是首先要在服务器上配置自签名的SSL证书,通过下列指令创建证书。

openssl genrsa -des3 -out thecodeway.com.key 1024
openssl req -new -key thecodeway.com.key -out thecodeway.com.csr
openssl rsa -in thecodeway.com.key -out thecodeway.com.nopass.key
openssl x509 -req -days 365 -in thecodeway.com.csr -signkey thecodeway.com.nopass.key -out thecodeway.com.crt


        然后是配置HTTP服务,我使用的是nginx做服务器,在vhost中添加一段

server {     
        listen       443;
        server_name  www.thecodeway.com thecodeway.com;
        ssl  on;     
        ssl_certificate   ./cert/thecodeway.com.crt;
        ssl_certificate_key ./cert/thecodeway.com.nopass.key;   

        access_log /srv/www/thecodeway.com/logs/access_ssl.log;
        error_log /srv/www/thecodeway.com/logs/error_ssl.log;
        root /srv/www/thecodeway.com/public_html;
        default_type text/html;

        location /{
                index index.php index.html index.html;
        }
}

        重启nginx之后,如果直接访问https域名,浏览器会出现安全警告,这是由于证书是自签名的伪证书造成的。现在要做的是在CloudFlare上注册账号,把你需要处理的域名加入,设置DNS解析,然后回到你的域名服务商那里,将域名的nameserver服务器设置成CloudFlare指定的服务器,然后打开域名的CloudFlare Setting选项,把其中的SSL选项设为“Full SSL”就可以了。
        等一段时间后,再通过https访问域名,就会发现原先的警告消失掉了,地址栏上换成了绿色的https图标,大功告成。
        Update:2015-12-30: 因为CloudFlare速度太慢,https又是鸡肋,关闭了
        Update:2017-04-21: 启用了Let’s Crypt的免费SSL证书

6 thoughts on “CloudFlare免费SSL证书使用

Foota进行回复 取消回复

邮箱地址不会被公开。

This site uses Akismet to reduce spam. Learn how your comment data is processed.