nvm安装成功后,关闭当前终端,重新连接
查看最新版本的Node.js并安装
nvm ls-remoteNVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node nvm install v8.1.4node -v
五、配置共享型MySQL并导入数据
创建MySQL成功后,选择管理操作,进入到phpmyadmin页面,选项导入
选择nideshop项目根目录下的nideshop.sql文件
六、本地部署NideShop
下载NideShop的源码
apt install git -ycd /var/www
安装ThinkJS
npm install thinkjs@2 -g --registry=https://registry.npm.taobao.org --verbosethinkjs --version
安装依赖
cd /var/www/nideshopnpm install --registry=https://registry.npm.taobao.org --verbose
配置mysql
vim src/common/config/db.js
修改后:
QQ截图20170715125320.png
启动:
npm start
curl localhost:8360
七 通过nginx、pm2进行线上部署
编译项目
npm run compile
修改nginx配置
/etc/nginx/sites-available/default修改后
server { listen 5050 default_server; server_name tumobi.applinzi.com; #注意:修改成你的域名
root /var/www/nideshop; set $node_port 8360; index index.js index.html index.htm; if ( -f $request_filename/index.html ){ rewrite (.*) $1/index.html break;
} if ( !-f $request_filename ){ rewrite (.*) /index.js;
} location = /index.js { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://127.0.0.1:$node_port$request_uri; proxy_redirect off; } location = /production.js { deny all;
} location = /testing.js { deny all;
} location ~ /static/ { etag on; expires max;
}
}
测试通过nginx访问
启动服务
node www/production.js
安装配置pm2
npm install -g pm2
修改项目根目录下的pm2.json为:
{"apps": [{ "name": "nideshop", "script": "www/production.js", "cwd": "/var/www/nideshop", "exec_mode": "cluster", "instances": 1, "max_memory_restart": "256M", "autorestart": true, "node_args": [], "args": [], "env": {
}
}
启动pm2
pm2 startOrReload pm2.json
八 修改NideShop微信小程序的配置
打开文件config/api.js,修改NewApiRootUrl为自己的域名,注册是https和后面的api/不能少
var NewApiRootUrl = 'https://tumobi.applinzi.com/api/';