现在https几乎成了每个站的标配,但是Hexo本身不支持SSL。
通过Google,发现大多数人的解决方案无非以下几种:
1.Hexo生成静态页面,再由Nginx发布网站
2.GitHub Pages/Coding等页面托管服务
3.CloudFlare等CDN
本次,我结合了此文章 记录一下,如何配置nodejs nginx的反向代理 利用Nginx反向代理Hexo来实现了https访问博客。

在部署好了Hexo并获取CA证书之后,你就可以开始工作了。
安装Nginx,并在你的Nginx配置文件中添加以下内容(请根据实际情况修改配置):

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
upstream nodejs {
server 127.0.0.1:4000; #此处填写Hexo开放端口
#server 127.0.0.1:3001;
keepalive 64;
}

server {
listen 80;
listen [::]:80;
server_name example.com; #你要绑定的域名
# enforce https
return 301 https://$server_name$request_uri; #http重定向https
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com; #你要绑定的域名
access_log D:/web/blog/logs/access.log; #网站访问日志文件存储位置
ssl_certificate ssl\ca.crt; #SSL证书文件存放为位置
ssl_certificate_key ssl\ca.key; #SSL证书文件存放为位置

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://nodejs; #此处似乎应该填为"http://localhost:4000"

}

}

重启Nginx,完成。