一、域名解析
1.登录 阿里云 -> 域名解析 - > 域名 指向
二、本地文件启动端口
movie-server/app.js 增加
var env = process.env.NODE_ENV || 'development' //获取当前环境变量 如没有 就为 开发模式
var dbUrl = 'mongodb://imooc_movie_runner:F**[email protected]: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": "[email protected]: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 [email protected]: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
[email protected]:/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;
八 、 本地部署