Let’s Encrypt 最近支持wildcard,顺便自己之前vps的东西也铲掉重来,所以这里是一篇再次部署Let’s encrypt证书的文章。

获取Acme工具

执行命令:

1
curl https://get.acme.sh | sh

进入 .acme.sh 目录。我用的是DigitalOcean的VPS,为了能用 wildcard,所以需要配置一下DNS相关的API来做域名的验证, 不能用standalone的模式,也就是自己启动服务器进行验证。详情可以看 ACME的dnsapi文档

按照文档exports了key后,执行如下命令:

1
~/.acme.sh# ./acme.sh --issue --dns dns_dgon -d *.nodecafe.me -d nodecafe.me

*.nodecafe.me是我自己的域名, -d参数表示部署不同域名 。

全程几乎5分钟搞定吧。

生成基于 DH 的密钥

具体原理自行谷歌,记住DH配合其他签名算法(RSA、DSA、EDSA)可防止中间人攻击就行了。

在你觉得方便管理的目录生成 dhparam.pem 文件,一般 dhparam.pem都会和其他证书在同一目录。

1
2
3
# 2048位算是在速度和安全性上的一种均衡选择

openssl dhparam -out dhparam.pem 2048

Nginx配置

安装过程不在阐述。 需要注意的地方是,我的VPS发行版是Ubuntu 16.04,似乎DO的Ubuntu是已经开启了ufw。需要让ufw允许http和https:

1
2
sudo ufw allow http
sudo ufw allow https

允许后,一般就默认能让80和443可4被访问了。

下面开始配置Nginx。

1
2
3
4
5
6
7
    server {
        listen 443 ssl;
        server_name nodecafe.me;
        ssl_certificate "YOURPATH/fullchain.cer";
        ssl_certificate_key "YOURPATH/*.nodecafe.me.key";
        ssl_dhparam "YOURPATH/dhparam.pem";
    }

执行 sudo service nginx configtest,验证一下配置是否正确。 出现

1
2
 * Testing nginx configuration
   ...done.

说明配置可用,执行sudo service nginx force-reload,用新配置重启Nginx。

之后需要反代你的域名到你到github page上,顺便处理http访问的情况,将http重定向到https。全部配置如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        server_name nodecafe.me
        rewrite ^(.*) https://nodecafe.me/$1 permanent;
        return 301 https://$host$request_uri;
        location / {
            try_files $uri $uri/ =404;

            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Methods GET,POST;

            proxy_pass https://yyydao.github.io/;
            proxy_redirect off;
            proxy_set_header Host yyydao.github.io;
            proxy_set_header X-Host yyydao.github.io;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}
server {
    listen 443 ssl;
    server_name nodecafe.me;
    ssl on;
    ssl_certificate "YOURPATH/fullchain.cer";
    ssl_certificate_key "YOURPATH/*.nodecafe.me.key";
    ssl_dhparam "YOURPATH/dhparam.pem";
        location / {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Methods GET,POST;

            proxy_pass https://151.101.73.147;
            proxy_set_header Host yyydao.github.io;
            proxy_set_header X-Host yyydao.github.io;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        X-Forwarded-Protocol    $scheme;
        }

}