### 一、部署git私有仓库
注意:推荐Centos或Uuntu系统,目前我用的是CentOS系统作为服务器
#### 1.1 安装git工具
[root@localhost ~]# yum -y install git
#### 1.2 创建git新用户并且设置密码
[root@localhost ~]# useradd git && echo git |passwd --stdin git
#### 1.3 创建git私有仓库
// 注意:先切换git用户在创建
[root@localhost ~]# su - git
[git@localhost ~]$ mkdir repo
[git@localhost ~]$ cd repo/
[git@localhost repo]$ git init --bare hexo.git
初始化空的 Git 版本库于 /home/git/repo/hexo.git/
[git@localhost repo]$ ls
hexo.git
[git@localhost repo]$ cd hexo.git/
[git@localhost hexo.git]$ ls
branches config description HEAD hooks info objects refs
git@localhost hexo.git]$ cd
#### 1.4 创建git私有仓库钩子
[git@localhost ~]$ cd /home/git/repo/hexo.git/
[git@localhost hexo.git]$ vim hooks/post-receive
[git@localhost hexo.git]$ cat hooks/post-receive
_#!/bin/bash_
repo\_path=/home/git/repo/hexo.git
hexo\_path=/var/www/hexo
git --work-tree=$hexo\_path --git-dir=$repo\_path checkout -f
[git@localhost hexo.git]$ chmod +x hooks/post-receive
[git@localhost hexo.git]$ chown -R git:git hooks/post-receive
### 二、部署Nginx站点
#### 2.1 安装nginx服务
[root@localhost ~]# yum -y install nginx
#### 2.2 查看用户id
[root@localhost ~]# id nginx
uid=996(nginx) gid=994(nginx) 组=994(nginx)
#### 2.3 备份nginx.conf文件
[root@localhost ~]# ls /etc/nginx/
conf.d fastcgi.conf fastcgi\_params koi-utf mime.types nginx.conf scgi\_params uwsgi\_params win-utf
default.d fastcgi.conf.default fastcgi\_params.default koi-win mime.types.default nginx.conf.default scgi\_params.default uwsgi\_params.default
[root@localhost ~]# cp -r /etc/nginx/nginx.conf{,.bak}
[root@localhost ~]# ls /etc/nginx/
conf.d fastcgi.conf fastcgi\_params koi-utf mime.types nginx.conf nginx.conf.default scgi\_params.default uwsgi\_params.default
default.d fastcgi.conf.default fastcgi\_params.default koi-win mime.types.default nginx.conf.bak scgi\_params uwsgi\_params win-utf
#### 2.4 编辑nginx.conf文件,并且修改内容
// 找到以下内容并且编辑
server {
listen 80;
listen [::]:80;
server\_name \_;
root /var/www/hexo;
index index.html index.php index.htm;
_# Load configuration files for the default server block._
include /etc/nginx/default.d/\*.conf;
error\_page 404 /404.html;
location = /404.html {
}
error\_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
#### 2.5 创建nginx站点和index.html文件
[root@localhost ~]# mkdir /var/www/hexo
[root@localhost ~]# chown -R git:git /var/www/hexo/
[root@localhost ~]# echo "hexo server myblog" >> /var/www/hexo/index.html
#### 2.6 nginx验证
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
注意:nginx服务启动后需要在浏览器上访问测试是否是显示index.html文件内容
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。