chaihongjun.me

免费升级网站至https

免费升级网站至https

letsencrypt是一个提供免费https证书的机构。随着https的盛行,国外包括国内很多的网站都已经或者即将迁徙到https,https不再是银行等行业的专属了。https的优点是什么,可以度娘。具体的迁移过程记录如下:

1.安装

首先进入letsencrypt的网站,https://certbot.eff.org/,选择WEB服务器和使用的linux版本,选择之后会打开一个新的页面,此处以nginx+centos6.8为例说明,打开的是https://certbot.eff.org/#centos6-nginx,然后按照页面的提示进行安装即可(root身份安装):

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

安装成功之后,会有如下类似提示:

Congratulations! Your certificate and chain have been saved at 
/etc/letsencrypt/live/xxx/fullchain.pem. Your cert will expire ...

接着是要修改nginx的配置文件了:

server {
    listen       443 ssl; #将80修改为443
    server_name     www.yourdomain.com
    #下面是密钥等文件配置
    ssl_certificate /etc/letsencrypt/live/xxxx/fullchain.pem;  
    ssl_certificate_key /etc/letsencrypt/live/xxx/privkey.pem;
}
#将所有的http请求跳转到https上,
server {
    listen 80;
    listen 443 ssl;
    server_name www.yourdomain.com yourdomain.com;
    return 301 https://www.yourdomain.com$request_uri;
}

保存以上配置然后重新nginx即可

2.续签

默认情况下的签名有效期是3个月,如果忘记续签的话网站就会出现签名错误,续签可以这样:

certbot-auto renew

但是还是不如自动续签来的方便:

./certbot-auto renew --dry-run 
./certbot-auto renew --quiet


知识共享许可协议本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。作者:柴宏俊»