网站搭建:通过Git部署到服务器
文章摘要
Efu GPT
此内容根据文章生成,并经过人工审核,仅用于文章内容的解释与总结
投诉安装 & 创建 Git用户
- 安装 Git
sudo apt-get install git
- 创建 Git 群组并添加git用户
# Ubuntu groupadd git useradd -g git git # Debian groupadd git usermod -a -g git git # CentOS groupadd git useradd -g git git
- 设置密码
passwd git
- 屏蔽git用户登录
vim /etc/passwd # 将git:x:1001:1001:,,,:/home/git:/bin/bash # 修改为git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
把/bin/sh改为/usr/bin/git-shell,用户就只能用来克隆或者推送数据到远程 git 仓库,而不能用它登录到主机。
配置Nginx
使用面板的话,可以直接在面板上配置
这里以1panel为例
- 创建站点,选择静态站点
/opt/1panel/apps/openresty/openresty/www/sites/efu.me/index
即为下一步中的工作目录
直接在Nginx配置文件中配置
server {
listen 80 ;
server_name www.efu.me;
index index.html;
root /www/sites/www.efu.me/index;
include /www/sites/www.efu.me/proxy/*.conf;
}
/www/sites/www.efu.me/index
即为下一步中的工作目录
创建裸仓库
- 新建一个裸仓库
mkdir -p /home/git/project/blog.git # -p 递归创建目录 cd /home/git/project/blog.git git init --bare --initial-branch=master # --bare 创建裸仓库 --initial-branch=master 创建主分支
- 设置权限
chown -R git:git /home/git/project/blog.git
- 配置钩子
添加以下内容vim hooks/post-receive
--work-tree
指定工作目录
(你在Nginx上设置的网站根目录),--git-dir
指定仓库目录#!/bin/bash git --work-tree=/home/git/project/blog --git-dir=/home/git/project/blog.git checkout -f
- 设置权限,让钩子可执行
chmod +x hooks/post-receive
配置Hexo
- 安装 hexo-deployer-git
npm install hexo-deployer-git --save
- 修改配置文件
deploy: type: git repo: ssh://git@你的服务器IP:/home/git/project/blog.git branch: master
- 部署
hexo clean hexo generate hexo deploy
- 进后台查看是否部署成功
- 感谢您的赞赏。
赞赏名单
因为有你们的支持,我才体会到写文章的价值。
本文是原创文章,采用CC BY-NC-SA 4.0协议,完整转载请注明来自Ever Fu
评论 ()