服务器环境

配置好服务器,准备好网站存放的目录并搭建好上传需要的环境。

部署到FTP服务器

使用 FTP 上传需要安装 ftp deployer 插件,命令 npm install hexo-deployer-ftpsync --save

修改 _config.yml 配置文件

1
2
3
4
5
6
7
8
9
10
11
#### ftp deploy
deploy:
type: ftpsync
host: ftpserver # ftp服务器地址
user: ftpusername # ftp用户名
pass: xxxx # 你的ftp用户密码
remote: xxx # 你要上传到的地址,例如/wwwroot
port: 21 # ftp端口,不同的ftp可能会不一样
delete: true # 上传本地文件是否删除ftp中的所有文件
verbose: true # 是否打印调试信息
ignore_errors: false # 是否忽略错误

最后,在执行完 hexo generate 网址生成之后,执行 hexo deploy 就可以了。

或者执行 hexo g -d 也是可以的。

部署到Git

使用 git 上传需要安装 git deployer 插件,命令 npm install hexo-deployer-git --save

修改 _config.yml 配置文件

1
2
3
4
5
6
### git deploy
deploy:
type: git
repo: https://github.com/cmlanche/cmlanche.github.io.git # 你的远程仓库
branch: master # 你的远程残酷分支
message: "hello guys" # 每次提交的信息

需要注意的是,部署到git需要再本地安装你ssh key,也就是说允许本地进行读写远程git仓库,否则你会没权限的

部署到远程主机,通常如VPS或者云服务器

同样需要安装 hexo deployer 插件,命令 npm install hexo-deployer-rsync --save

修改 _config.yml 配置文件

1
2
3
4
5
6
7
8
9
10
deploy:
type: rsync
host: <host> # 主机地址
user: <user> # 用户名
root: <root> # 要上传到的目录
port: [port] # Default is 22
delete: [true|false] # Default is true
args: <rsync args>
verbose: [true|false] # Default is true
ignore_errors: [true|false] # Default is false

问题记录

执行 hexo deploy 提示 INFO Validating config ?

原因是在修改 _config.yml 配置文件时,在类似 type: ftpsync 这种配置文件键值对 : 的后面没有加一个空格导致。

如果出现这种问题可以看看是不是在键值对的 : 后面没有加一个空格所导致。