简介
本指南介绍如何在 Ubuntu 服务器上部署 Hexo 博客,并集成 Trojan HTTPS 代理。
系统环境
- 系统: Ubuntu 20.04 LTS
- Web 服务器: Nginx 1.18.0
- 博客引擎: Hexo
- HTTPS: Trojan
架构说明
1 2 3 4 5 6 7
| 用户 → HTTPS:443 (Trojan + SSL) ↓ Nginx:80 ↓ / → 博客(Hexo 静态文件) /openclaw/ → OpenClaw Gateway:18789 /apps/ → 应用展示
|
安装 Hexo
1. 安装 Hexo CLI
2. 创建博客
1 2 3
| mkdir -p /var/www/yourdomain cd /var/www/yourdomain hexo init blog
|
3. 配置博客
编辑 _config.yml:
1 2 3 4 5 6 7 8 9 10 11
| title: Your Site Name subtitle: '技术博客' description: '个人技术博客' keywords: 技术,博客 author: Your Name language: zh-CN timezone: 'Asia/Shanghai'
url: https://yourdomain.com
|
4. 生成静态文件
1
| hexo clean && hexo generate
|
配置 Nginx
1. 创建配置文件
编辑 /etc/nginx/sites-enabled/yourdomain.conf:
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
| server { listen 80; server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain/blog/public; index index.html index.htm;
location / { try_files $uri $uri/ =404; }
location /api/ { proxy_pass http://127.0.0.1:3000/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }
gzip on; gzip_types text/plain text/css application/json application/javascript; gzip_min_length 1000; }
|
2. 测试并重启
1 2
| nginx -t systemctl reload nginx
|
配置 Trojan
1. 安装 Trojan
1 2 3 4
| wget https://github.com/trojan-gfw/trojan/releases/download/v1.16.0/trojan-1.16.0-linux-amd64.tar.xz tar -xf trojan-1.16.0-linux-amd64.tar.xz mv trojan /usr/src/
|
2. 配置
编辑 /usr/src/trojan/server.conf:
1 2 3 4 5 6 7 8 9 10 11 12
| { "run_type": "server", "local_addr": "0.0.0.0", "local_port": 443, "remote_addr": "127.0.0.1", "remote_port": 80, "password": ["your_password"], "ssl": { "cert": "/path/to/fullchain.cer", "key": "/path/to/private.key" } }
|
3. 创建 Systemd 服务
编辑 /etc/systemd/system/trojan.service:
1 2 3 4 5 6 7 8 9 10
| [Unit] Description=trojan After=network.target
[Service] ExecStart=/usr/src/trojan/trojan -c /usr/src/trojan/server.conf Restart=always
[Install] WantedBy=multi-user.target
|
4. 启动服务
1 2 3
| systemctl daemon-reload systemctl enable trojan systemctl start trojan
|
SSL 证书
使用 Let’s Encrypt
1 2 3 4 5 6 7 8 9
| apt-get install -y certbot
certbot certonly --standalone -d yourdomain.com
|
自动续期
1 2 3 4 5 6 7
| certbot renew --dry-run
crontab -e
0 3 * * * certbot renew --quiet
|
博客管理
创建文章
1 2
| cd /var/www/yourdomain/blog hexo new "文章标题"
|
编辑文章
生成部署
1
| hexo clean && hexo generate
|
管理脚本
创建 deploy.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #!/bin/bash BLOG_DIR="/var/www/yourdomain/blog"
case "$1" in "new") cd $BLOG_DIR shift hexo new "$@" ;; "generate"|"g") cd $BLOG_DIR hexo clean && hexo generate ;; *) echo "用法: $0 {new|generate}" ;; esac
|
常见问题
502 Bad Gateway
检查后端服务是否正常运行。
HTTPS 证书错误
- 确认证书路径正确
- 确认证书未过期
- 重启 Trojan 服务
Hexo 生成失败
- 检查文章格式
- 检查
_config.yml 语法
- 查看错误日志
相关文档: