传送门

  1. Hexo 之旅
  2. Hexo 博客部署到 Ubuntu 服务器
  3. Ubuntu 下为 Nginx 添加 SSL 证书    ⇦当前位置📌
  4. 多端实现 Hexo 文章发布

前置条件

  • 服务器上安装了 Hexo
  • 域名和 SSL 证书,二者需要绑定
  • 服务器上已经安装了 Nginx
  • 服务器的 80 和 443 需要开启

证书下载和上传

  • 证书可以从阿里云申请,也可以从腾讯云申请
  • 以腾讯云的免费证书为例,在 SSL 证书管理页面,申请免费证书并且绑定好域名,点击下载
  • 选择 Nginx,然后将 crtkey 尾缀的文件上传到服务器的一个确定位置,如,/etc/nginx/

配置文件

  • 以修改配置文件 default 为例,位置:/etc/nginx/sites-enabled/default
# 在配置 80 端口的 server 中,location / {} 里面将其重定向到 https
server {
listen 80;
server_name www.example.com example.com;
location / {
return 301 https://$host$request_uri;
}
}

# 在配置 443 端口的 server 中,添加 ssl 证书
# 新写一个 server 配置
server {
listen 443 ssl;
server_name {填写域名};
# 上传的两个证书文件的路径
ssl_certificate {服务器上 .crt 文件位置};
ssl_certificate_key {服务器上 .key 文件位置};
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# 配置https服务默认路径 此处根据自己的服务而定
location / {
# root 这里选择自己的网站根目录
root /var/www/hexo;
index index.html index.htm;
}
}