http://pm2.keymetrics.io/node
module.exports = { apps: [{ name: "blogserver", script: "./code/server/index.js", env: { "NODE_ENV": "production" }, env_production: { "NODE_ENV": "production" } }], deploy: { production: { user: "root", host: ["47.94.208.76"], port: "8290", // SSH options with no command-line flag, see 'man ssh' // can be either a single string or an array of strings ssh_options: "StrictHostKeyChecking=no", // GIT remote/branch ref: "origin/master", // GIT remote repo: "git@gitee.com:tian_zz/blog.git", // path in the server
path: "/www/my-blog/blogserver",
env: { "NODE_ENV": "production" } }, } }
mkdir /wwwnginx
cd /wwwgit
mkdir my-blognpm
cd my-blog後端
一、本地 pm2 deploy ecosystem.config.js production setup服務器
二、服務器端會看到多出的文件夾: app
pm2 deploy ecosystem.config.js productionssh
pm2 list tcp
發現報錯,打印下日誌:pm2 logs blogserver post
沒有找到模塊,進入服務器/www/my-blog/blogserver/source目錄:npm install 安裝包,再回到本地從新部署一下 pm2 deploy ecosystem.config.js production,回到服務器:部署成功。
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --permanent --list-port
firewall-cmd --reload
cd /etc/nginx/conf.d
upstream locusy { server 127.0.0.1:3000; } server { listen 80; server_name www.locusy.top; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Nginx-Proxy true; proxy_pass http://locusy; proxy_redirect off; } }
重啓nginx:nginx -s reload