• 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]# 
  • 相关阅读:
    JGUI源码:右键菜单实现(12)
    JGUI源码:开发中遇到的问题(11)
    JGUI源码:prefixfree 这个库有时候会引起网页一直加载中(10)
    Ext.net按钮事件中使用Response.Redirect的一个问题
    JGUI源码:Tab组件实现(9)
    IE7下使用兼容Icon-Font CSS类
    JGUI源码:JS菜单动态绑定(8)
    JGUI源码:组件及函数封装方法(7)
    JQuery对象关系图
    JGUI源码:Accordion折叠到侧边栏实现(6)
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/6373366.html
Copyright © 2020-2023  润新知