Egg.js部署

2020-05-25 / 436

本文环境基于Ubuntu

Node

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
nvm install --lts
npm install -g cnpm --registry=https://registry.npm.taobao.org

Code

sudo apt install -y git
git clone git@gitlab.zeaho.com:node/saas-admin-server.git
cd saas-admin-server && cnpm i

Redis & MySQL

sudo apt install -y docker.io
sudo docker run --name redis-egg -p 6379:6379 -d redis
sudo docker run --name mysql-egg -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.17
sudo docker exec -i mysql-egg mysql -uroot -p123456  <<< "CREATE DATABASE IF NOT EXISTS zhg DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
sudo docker exec -i mysql-egg mysql -uroot -p123456 zhg < ./test/users.sql

Service

cd saas-admin-server && cnpm start

Nginx

sudo apt install -y nginx
sudo vim /etc/nginx/sites-enabled/sa-node.zhgcloud.com
server {
    listen 80;
    server_name sa-node.zhgcloud.com;

    location / {
        proxy_pass http://localhost:7001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

重启nginx

sudo nginx -t
sudo nginx -s reload

Hosts

sudo sh -c "echo '47.75.67.227 sa-node.zhgcloud.com' >> /etc/hosts"
curl sa-node.zhgcloud.com # hi, egg