使用pm2優雅的讓你的項目自動發佈上線

使用pm2優雅的讓你的項目自動發佈上線html

標籤(空格分隔): pm2nginx

本文首發: https://shudong.wang/10613.html

目的:git

在本地執行命令,而後讓服務器自動把你的代碼從git上面拉去到服務器上面。每次都自動化,不須要手工去登陸服務器下載代碼,或拷貝。

前提:github

把本身的項目推送到git倉庫
固然若是是本身的公司項目,確定不想讓項目公開。
能夠使用私有倉庫,
而後再github的私有倉庫收費很貴 20$ 每個月

下面介紹一些私有倉庫不收費的
國產開源中國
git.oschina.net
國產
coding.net

gitlab.com

生成祕鑰
ssh-keygen -t rsa -C 'wsd312@163.com'

更改防火牆端口
vim /etc/iptables.rules

使用nginx 反向代理轉發
能夠把 3000  8080
這些端口轉發到 80

www.shudong.wang:3000/index.html
80

第一步建立一個 ecosystem.json 文件

第二步寫ecosystem.json配置文件

{
    "apps": [{
        "name": "student",
        "script": "app.js",
        "env": {
            "COMMON_VARIABLE": "true"
        },
        "env_production": {
            "NODE_ENV": "production"
        }
    }],
    "deploy": {
        "production": {
            "user": "ubuntu",
            "host": ["主機ip"],
            "port": 22,
            "ref": "origin/master",
            "repo": "https://git.oschina.net/shudongwang/student.git",
            "path": "/home/ubuntu/www",
            "ssh_options": "StrictHostKeyChecking=no",
            "env": {
                "NODE_ENV": "production"
            }
        }
    }
}

第三部執行

下面的命令是按照你的配置文件把本地的代碼發佈到服務器上面,用戶初始化。json

pm2 deploy ecosystem.json production setupubuntu

之後更改代碼後使用下面這個命令發佈
pm2 deploy ecosystem.json productionvim


本篇文章由一文多發平臺ArtiPub自動發佈服務器

相關文章
相關標籤/搜索