查看系统版本
cat /etc/redhat-release
我的系统版本CentOS Linux release 7.6.1810 (Core)
安装node
yum -y install nodejs
安装完成后,验证node
是否安装成功
node -v
出现版本号代表安装成功,此时版本偏低,可以安装n模块
来升级版本
npm install -g n
更新升级node
版本
n stable // 把当前系统的 Node 更新成最新的 “稳定版本”
n lts // 长期支持版
n latest // 最新版
n 10.14.2 // 指定安装版本
验证版本,如果发现版本还是之前的版本,可以断开远程连接重连,再次验证版本
安装nginx
yum -y install nginx
查看安装位置
whereis nginx
执行目录:/usr/sbin/nginx
模块所在目录:/usr/lib64/nginx
配置所在目录:/etc/nginx
默认站点目录:/usr/share/nginx
相关命令
systemctl status nginx.service // 查看状态
systemctl start nginx.service // 启动
systemctl reload nginx.service // 重启
systemctl stop nginx.service // 停止
安装pm2
npm i pm2 -g
安装完成后,给pm2
添加开机自启动
pm2 startup systemd
pm2 save
部署项目
-
把打包好的
vue
项目复制到/usr/share/nginx
路径下 -
修改
/etc/nginx
路径下的nginx.conf
文件
找到相关代码并注释掉 -
在
/etc/nginx/conf.d
路径下新增后缀.conf
文件
server {listen 80;listen [::]:80;server_name _;location / {root /usr/share/nginx/你的项目文件夹名称;index index.html index.htm;try_files $uri $uri/ /index.html;}
}
- 启动
nginx
nginx -t // 检测配置文件是否正常
systemctl start nginx.service // 启动
- 把
express
项目复制到/root
路径下,进入项目文件夹下并启动
npm install // 安装项目相关依赖
pm2 start ./bin/www // 启动
- 配置
nginx
文件,对express
项目做反向代理
在/etc/nginx/conf.d
路径下新增后缀.conf
文件
server {listen 你想设置的端口号;listen [::]:和上面的端口号一致;server_name _;location / {proxy_pass http://127.0.0.1:3000/;}
}
- 重启nginx,大功告成
systemctl reload nginx.service // 重启