pm2用法之ecosystem部署nodejs

匿名 (未验证) 提交于 2019-12-03 00:37:01



在项目根目录添加pm2的部署脚本文件 ecosystem.json

{     "apps": [         "name": "movie", //对应Nginx上的配置         "script": "app.js", //入口文件         "env": {             "COMON_VARIABLE": "true"         },         "env_production": {             "NODE_ENV": "production"         }     ],     "deploy": {         "production": {             "user": "poetries", //Nginx服务器上的username             "host": ["120.120.14.21"], // 服务器地址             "port": "3922",             "ref": "origin/master", //从指定的分支拉取代码             "repo": "git@github.com:poetries/poetries.github.io.git",             "path": "/www/movie/production",//发布到服务器指定的目录下             "ssh_options": "StrictHostKeyChecking=no",             //构建在发布             "post-deploy": "npm install --registry=https://registry.npm.taobao.org && grunt build && pm2 startOrRestart ecosystem.json --env production",             "env": {                 "NODE_ENV": "production"             }         }     } }

nginx安装目录下的vhost中新建一个xx-3000.conf的配置文件

upstream movie { // website项目的目录名称     server 127.0.0.1:3000; // 服务器上的本地启动入口 }  // 配置server server {     listen 80;     server_name movie.poetries.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://movie; // 对应上面的目录         proxy_redirect off;     }      // 处理静态资源     location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt) {         root /www/movie/public; //静态资源路径     } }

Ubuntu的设置

  • 打开 sudo vi /etc/iptables.up.rules
  • 生效 sudo iptables-restore < /etc/iptables.up.rules
# movie -A INPUT -s 127.0.0.1 -p tcp --destination-port 3001 -m state ESTABLISHED -j ACCEPT  -A OUTPUT -s 127.0.0.1 -p tcp --destination-port 3001 -m state ESTABLISHED -j ACCEPT
  • pm2 deploy ecosystem.json production setup 初始化
  • pm2 deploy ecosystem.json production 部署
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!