zoukankan      html  css  js  c++  java
  • Git 部署 Web 网站

    /***************************************************************************
     *                         Git 部署 Web 网站
     * 说明:
     *     主要是想自动部署静态网站到自己的VPS上,这样做的目的是方便像github
     * pages那样更新内容。
     *
     *                                      2017-2-7 深圳 南山平山村 曾剑锋
     **************************************************************************/
    
    一、参考文档:
        1. 处理git clone命令的非标准SSH端口连接
            http://nanxiao.me/git-clone-ssh-non-22-port/
        2. 使用Git来部署一个Web站点笔记
            http://rmingwang.com/using-git-to-deploy-a-web-site.html
    
    二、操作步骤:
        1. VPS安装Web相关软件,nginx、Apache,选自己擅长的就行;
        2. VPS生成git SSHkey,主要是提交代码的时候使用SSH来提交;
        3. 把自己的id_rsa.pub文件内容拷贝到VPS的/~/.ssh/authorized_keys文件里,一行一个;
        4. 在VPS上创建git仓库:
            git init --bare demo.git
        5. 在demo.git的hooks创建post-receive文件并添加:GIT_WORK_TREE=/home/zengjf/www git checkout -f,操作如下:
            [root@localhost demo.git]# cd hooks/
            [root@localhost hooks]# ls
            applypatch-msg.sample  post-receive.sample    pre-rebase.sample
            commit-msg.sample      post-update.sample     prepare-commit-msg.sample
            post-commit.sample     pre-applypatch.sample  update.sample
            post-receive           pre-commit.sample
            [root@localhost hooks]# pwd
            /home/zengjf/demo.git/hooks
            [root@localhost hooks]# cat post-receive
            GIT_WORK_TREE=/home/zengjf/www git checkout -f
            [root@localhost hooks]# 
        6. 在开发机上写好内容,git add、git commit,最后推送到VPS服务器上,命令大致如下:
            git push ssh://root@21.106.105.15:7841/home/zengjf/demo.git master
        7. 自动在web目录生成了想要的推送文件:
            [root@localhost www]# ls
            index.html
            [root@localhost www]# cat index.html 
            zengjf
            two times
            three times
            four times
            five times
            [root@localhost www]# pwd
            /home/zengjf/www
            [root@localhost www]# 
  • 相关阅读:
    新学期——扬帆起航
    我与虚拟机的爱恨情仇
    20155329胡佩伦的第二次预备作业——再思考
    课前的第一次与老师交流
    # 20155327 2016-20017-3 《Java程序设计》第3周学习总结
    20155327《Java程序设计》第二周学习总结
    20155327 2016-2017-2 《Java程序设计》第一周学习总结
    20155327第三次作业
    20155327 学习基础和C语言基础调查
    记自己的第一篇博客
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/6373366.html
Copyright © 2011-2022 走看看