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]# 
  • 相关阅读:
    Day01
    微前端技术框架qiankun技术分享
    终于有人把O2O、C2C、B2B、B2C的区别讲透了
    Electron-Vue项目使用Element的el-table组件不显示
    monaco editor各种功能实现总结
    electron-vue项目使用elementUI组件报错$attrs is readonly
    monaco-editor 使用总结
    闲谈Monaco Editor-基本使用
    【软件】MATHTYPE破解记
    C# EF
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/6373366.html
Copyright © 2011-2022 走看看