ohto-ai
ohto-ai
thatboy
1 post
Drop
Don't wanna be here? Send us removal request.
ohto-ai · 5 years ago
Text
哪个男孩子不想拥有一个git同步的网站呢?
服务器创建git用户
addusr git passwd git
创建信任关系
Tip: 每次提交就不用输入密码了
本地创建key公钥证书
ssh-keygen -t rsa -C "[email protected]" cat ~/.ssh/id_rsa.pub
复制公钥到服务器
ssh-copy-id -i .ssh/id_rsa.pub [email protected]
如果不识别ssh-copy-id指令,可以手动替换(建议加在authorized_keys结尾)
scp -p ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys
赋予权限
chomd 700 .ssh cd .ssh & chmod 600 authorized_keys
Tip: 可以修改git用户的权限,比如禁止登录等
修改ssh认证
sudo vim /etc/ssh/sshd_config RSAAuthentication yes #开启RSA认证功能 PubkeyAuthentication yes #开启公匙认证 StricModes no #不强���要求登录用户和文件拥有者用户相同
初始化git仓库
su root cd /usr/repos && git init --bare website.git chown -R git.git website.git
本地测试推送
略(git bash/github-desktop)
[email protected]:/usr/repos/website.git
服务器clone
略(git账户)
[email protected]:/usr/repos/website.git
利用钩子编写自动执行程序
touch /usr/repos/website/hooks/post-receive chmod -R 777 /usr/repos/website/hooks/post-receive vim /usr/repos/website/hooks/post-receive
内容如下
#!/bin/sh git --work-tree=/usr/website --git-dir=/usr/repos/website.git checkout -f
设置nginx目录
Tip: 需要管理员账户修改nginx.conf
sudo vim /usr/local/nginx/conf/nginx.conf
修正http和https为正确目录
# http部分 location / { root /usr/website; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/website; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/website; } # https部分 location / { root /usr/website; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/website; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/website; }
打完手工
sudo /usr/local/nginx/sbin/nginx -s reload
在本地修改好网站即可通过git提交修改,可以避免每次都要手动同步被修改的文件的痛苦。
补充
网站目录可搬迁,注意一下钩子的指令,最好执行一次以同步。
如果使用hexo等工具搭建可以更方便的修改提交哟,这里针对的是自己写的静态网站。
1 note · View note