node服务器项目部署 - (电影网站)

查看更多资源

一、域名解析

1.登录 阿里云 -> 域名解析 - > 域名 指向

二、本地文件启动端口

movie-server/app.js  增加

var env = process.env.NODE_ENV || 'development'  //获取当前环境变量 如没有 就为 开发模式

var dbUrl = 'mongodb://imooc_movie_runner:F**k9001$@127.0.0.1:19999/imooc-movie'
//链接线上数据库

if (env === 'development') {  //开发模式 链接 本地数据库
  dbUrl = 'mongodb://localhost/imooc-movie'
}

三、新建发布脚本

movie-server/ecosystem.json

{
  "apps": [
    {
      "name": "Movie",  //名字
      "script": "app.js",  // 入口文件
      "env": {
        "COMMON_VARIABLE": "true"
      },
      "env_production": {
        "NODE_ENV": "production"
      }
    }
  ],
  "deploy": {
    "production": {
      "user": "你的服务器登录用户名",
      "host": ["你的服务器 IP"],
      "port": "你的服务器登录端口",
      "ref": "origin/master",
      "repo": "git@gitee.com:guiyangyang/backend-movie.git",//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"
      }
    }
  }
}

四、版本控制

1. 码云上  新建项目 backend-move ->

2. 本地cmd进入website-sever:

1. 设置git全局 用户名 、邮箱
git config --global user.name "小羊"
git config --global user.email ""

2.确保该仓库是干净的
ll -a   // 没有.git 文件

git init

git add .
git commit -m 'first'

git remote add origin git@gitee.com:guiyangyang/backend-movie.git

git push  -u origin master

//提交失败  原因  远程仓库生成了lession  需要 先更新下来


git fetch

git merge origin/master  // 进入vi  直接 :wq!

git push  -u origin master


//git pull --rebase origin master   //远程 生成 readme
git push  -u origin master




五、服务器创建项目地址

1.登录 xiaoyang_manager
mkdir www
cd www
mkdir movie

sudo chmod 777 -R movie     //授权

六、movie-server/.gitignore

lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
public/build
public/build/*
results

npm-debug.log
node_modules
*.graffle
bower_components
.DS_Store

七、修改nginx

1.
cd /etc/nginx/conf.d
ls   //已经有一份  进行复制 1539-ink-8081.conf
sudo cp 1539-ink-8081.conf movie-iblack-com-3001.conf

xiaoyang_manager@nodeFirst:/etc/nginx/conf.d$ sudo vi movie-iblack-com-3001.conf
upstream movie{
  server 127.0.0.1:3001;
}

server {
 listen 80;
 server_name movie.1539.ink;

 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/productions/current/public;

八 、 本地部署

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值