惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
Engineering at Meta
Engineering at Meta
I
InfoQ
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 【当耐特】
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
腾讯CDC
雷峰网
雷峰网
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
D
Docker

Fooleap's Blog

渴望理想 | Fooleap's Blog 19 年底一些事 | Fooleap's Blog 藉秋风,跑起来 | Fooleap's Blog 一个人去跑步 | Fooleap's Blog 8 月的跑量仿佛是那暑假的作业 | Fooleap's Blog 三伏天跑步那么难受,为何还要跑? | Fooleap's Blog 解决小程序开发“当前系统代理不是安全代理” | Fooleap's Blog 忘却配速的夏日跑步 | Fooleap's Blog 六月天时“带水”跑步更爽 | Fooleap's Blog 出来混迟早要还的 | Fooleap's Blog 跑步不能当饭吃 | Fooleap's Blog 将京东移动端详情页链接转为 PC 端 | Fooleap's Blog 不是热就是雨 | Fooleap's Blog 这半月,我跑了 11 个 520 | Fooleap's Blog 跑完流汗一时爽,一直流汗一直爽 | Fooleap's Blog 初夏夜跑 | Fooleap's Blog Electron 中打开 QQ 临时会话 | Fooleap's Blog 春节期间的培隆角 | Fooleap's Blog 从春天跑到夏天 | Fooleap's Blog 晨雾中奔跑 | Fooleap's Blog 漫步春雨中 | Fooleap's Blog 跑在木棉花下 | Fooleap's Blog 我在春节依然坚持跑步 | Fooleap's Blog 伴随着日出跑步 | Fooleap's Blog 没有最好,只有更好 | Fooleap's Blog 电子气温计 | Fooleap's Blog 渡亭小学的金凤花 | Fooleap's Blog 随心而跑 | Fooleap's Blog 2018 跑步小结 | Fooleap's Blog 在 gVim 中使用“非等宽字体” | Fooleap's Blog
使用 Git 管理静态网站 | Fooleap's Blog
fooleap · 2013-01-10 · via Fooleap's Blog

本博使用 GitHub Pages,很喜欢使用 Git 这种方式管理网站,下面就一起来看看如何使用 Git 来管理静态网站

以下参考这篇文章 Using Git to manage a web site

假设有一台 VPS,它的域名是 fooleap.org,我们可以通过 SSH 登录进行操作

先在服务器上创建一个新账户 git

$ ssh root@fooleap.org 'adduser git'

SSH 自动登录

使用公钥互信实现自动登录

$ ssh git@fooleap.org 'mkdir .ssh'
$ ssh git@fooleap.org 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
  • 在服务器的 ~/.ssh/authorized_keys 文件添加本地公钥

可以在本地的 ~/.ssh/config 文件定义 host git 对应的主机名及用户名

~/.ssh/config
host git
hostname fooleap.org
user git

经过这样处理之后,我们就可以通过 ssh git 自动登录服务器

服务器端

$ mkdir web.git && cd web.git
$ git --bare init
  • 初始化,添加 bare 参数是为了创建一个裸仓库,即不包含工作目录
./hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=~/web git checkout -f
$ chmod +x hooks/post-receive
  • 在挂钩目录 hooks 下创建一个 post-receive 文件,并赋予它可执行权限

这么做的作用是什么呢?

当我们在本地执行推送后,会自动执行这个脚本,将 ~/web 这个目录作为工作目录并进行 checkout 操作

$ cd && mkdir web 
  • 创建工作目录,这个目录可通过 Nginx 等设置对其访问

为用户 git 指定一个专用的 shell

/etc/passwd
- git:x:1001:1000:,,,:/home/git:/bin/bash
+ git:x:1001:1000:,,,:/home/git:/usr/bin/git-shell
  • 将默认的 shell: bash 替换为 git-shell

这是为多人管理网站做的准备,作为协作管理的权限

客户端

$ mkdir web && cd web
$ git init
$ echo "Hello World" > index.html
$ git add .
$ git commit -m "add index.html"
$ git remote add web git@fooleap.org:web.git
$ git push web +master:refs/heads/master
  • 初始化本地仓库,提交一个版本,添加远程仓库并推送

以后我们就可以在使用 git 来维护静态网站,要更新服务器端的时候,只需轻轻一推

鄙人外语能力不足,没法和原文一样详细描述,Git 的使用也是半桶屎,有哪里说错,还请指出

参考资料

本文历史

  • 2013 年 01 月 10 日 完成初稿

最近更新

猜你喜欢