在自己的服务器上部署hexo博客
前言
因为我有一个腾讯云的服务器,配置如下:
- CentOS7.2 X64
- 1 GB RAM
我想在服务器IP上构建一个hexo博客。
- 在云服务器上配置git
- 配置服务器上的Nginx
- 调整您自己的本地计算机中的Hexo
通过执行以上简单步骤,您也可以拥有自己的网站。废话不多,让我们开始吧!
云服务器准备
进入您的云服务器控制台
你知道该怎么做
在您的服务器上安装Git
安装依赖项和编译工具
安装依赖项
1
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
安装编译工具
1
yum install gcc perl-ExtUtils-MakeMaker package
安装 git
1
yum install git
检查git版本
1
git --version
如果此命令有效并在您的服务器console上显示git版本,则说明您已成功安装git
找不到git命令
如果遇到此问题,请在服务器上配置环境变量
将git添加到PATH
1
echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
使git环境变量生效
1
source /etc/bashrc
再次尝试步骤3
使Git在您的服务器上正常工作
在这一步中,我们将在home / git中创建一个名为hexoBlog的空仓库,并配置目录的权限。并创建一个新的git hook以进行自动部署。
创建目录并配置权限
1
2
3mkdir /home/git/
chown -R $USER:$USER /home/git/
chmod -R 755 /home/git/创建空的git仓库
1
2cd /home/git/
git init --bare hexoBlog.git创建一个新的git hook以进行自动部署(需要Vim知识)
1
vim /home/git/hexoBlog.git/hooks/post-receive
将这些代码放入打开的文件中。
1
git --work-tree=/home/hexoBlog --git-dir=/home/git/hexoBlog.git checkout -f
保存并退出。
修改文件权限以使其可执行。
1
chmod +x /home/git/hexoBlog.git/hooks/post-receive
在服务器上配置Nginx
安装 Nginx
1
yum install -y nginx
运行 Nginx
1
service nginx start
测试 Nginx 服务
1
wget http://127.0.0.1
如果您在控制台上收到类似这样的消息,则说明您已正确安装nginx。
1
2
3
4
5
6
7
8Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43704 (43K) [text/html]
Saving to: ‘index.html’
100%[=======================================>] 43,704 --.-K/s in 0s
2018-03-09 23:04:09 (487 MB/s) - ‘index.html’ saved [43704/43704]尝试在浏览器中输入服务器IP地址进行测试
配置Nginx托管目录
创建用于Nginx托管的home / hexoBlog目录
1
2
3mkdir /home/hexoBlog/
chown -R $USER:$USER /home/hexoBlog/
chmod -R 755 /home/hexoBlog/检查Nginx的安装位置
1
nginx -t
配置(需要Vim知识)
1
vim /etc/nginx/nginx.conf
修改文件
1
2
3
4
5
6
7
8
9
10
11server {
listen 80 default_server;
listen [::]:80
default_server;
root /home/hexoBlog; #Need Modify here
server_name icimence.cn; #Need Modify here
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {}
error_page 404 /404.html;
location = /40x.html {}重新启动Nginx服务
1
service nginx restart
修改计算机上的本地文件
在Hexo根目录下打开_conig.yml
1
2
3
4deploy:
type: git
repo: root@'Your IP address here':/home/git/hexoBlog
branch: master运行hexo deploy命令
1
hexo d
大功告成
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 icimence's Tech Blog!
评论