hexo部署到个人云服务器

hexo部署到个人云服务器

服务器和域名购买就不讲了,这个就不讲了,重点讲讲Nginx配置和git配置。

1.nginx安装及配置

安装

yum install -y nginx

安装完成后启动 nginx 服务器,命令如下:

systemctl start nginx
systemctl enable nginx

配置

创建目录并修改目录所有权和权限,目录位置自己确定:

mkdir -p /var/www/hexo

chown -R $USER:$USER /var/www/hexo
chmod -R 755 /var/www/hexo

配置 nginx 路由:

vim /etc/nginx/conf.d/mysite.conf

添加如下内容
 server{        listen    80;
               root /var/www/hexo;
               #server_name test.top;
               location /{        
               }
}

2.配置服务端Git

安装Git

yum install git

建立文件路径:

mkdir /root/gitrepo/

修改权限:

chown -R $USER:$USER /root/gitrepo/
chmod -R 755 /root/gitrepo/

创建远程 Git 仓库:

cd /root/gitrepo/
git init --bare {
    
    自定义仓库名name}.git
Git 钩子(hooks)

执行下面的命令,在生成的仓库{自定义仓库名name}/hooks 目录下创建一个新的钩子文件:

vim /root/gitrepo/hexo.git/hooks/post-receive

打开文件添加下面的代码:

#!/bin/bash

git --work-tree=/usr/share/nginx/mysite --git-dir=/root/gitrepo/hexo.git checkout -f

赋予该文件可执行权限:

扫描二维码关注公众号,回复: 15943305 查看本文章
chmod +x /root/gitrepo/hexo.git/hooks/post-receive

3.设置 SSH Key 免密登录服务器

服务器登陆然后找到 .ssh 目录,如果没有的话,就新建并赋予权限:
mkdir .ssh && chmod 700 .ssh
然后接着新建文件authorized_keys:
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
查看repo的用户信息
git config -l
本地查看是否在.ssh下有公钥私钥,如果没有需要创建:
ssh-keygen

将本地id_rsa.pub中的公钥复制粘贴添加到authorized_keys中

4. 使用 Git 部署本地 Hexo 到远端服务器

在本地任意目录执行如下命令:

git clone root@{云服务器IP}:/root/gitrepo/hexo.git

编辑站点配置文件_config.yml , 将 url 改成https://{云服务器IP}/

将 deploy 目标改为 {服务器用户名}@{服务IP}:/var/repo/hexo.git

进入站点目录,执行hexo clean && hexo g -d 部署站点。

猜你喜欢

转载自blog.csdn.net/penguinli/article/details/131922332
今日推荐