阿里云服务器
Centos 64位 7.6 用户名都叫做root!
1.改密码 重启实例 233243 (改密码后需要重启实例才会有效!!)
2.远程控制 记录一个密码! ( git黑窗口 ssh root@公网IP 47.96.0.211)
3.配置安全组 1/60000 0.0.0.0/0 (ls cd / )
4.安装node.js
现在可以使用yum命令安装Node.js了。
sudo yum install nodejs
5.安装nginx服务器(静态服务器)
https://www.linuxidc.com/Linux/2016-09/134907.htm
/software/niginx-1.10.3.tar.gz
cd software
tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure make make install
6.装好了之后直接访问公网 47.96.0.211
/usr/local/nginx/html/ ===> 文件存放位置
npm install pm2 -g (全局安装pm2)
可能会报错:
spawning pm2 daemon with pm2_home=/root/.pm2
解决办法:(升级node最新稳定版本)
*npm install -g n
*n stable
(升级node为12.18的版本了 重新开启黑窗口)
pm2 list
pm2 start ./bin/www --name = “名称”
pm2 delete id 删除
pm2 stop id 停掉
pm2 restart id 重启
部署线上接口
1)本地运行express-pro项目,开启本地数据库,配合postman接口进行调试,测验OK了。
2)远程创建 node-pro
-
不要忘记执行
-
npm install nodemon -g
-
npm i
3)想要长期挂起服务,需要安装pm2
npm instal pm2 -g
pm2 start ./bin/www --name “express接口”
后续 pm2的命令:
pm2 start 启动服务id
pm2 delete 删除服务id
pm2 restart 重启服务id
4)直接用postman进行接口测试
http://公网IP:3000/api/user/loginin (post请求 username/password)