阿里云centos部署jsonserver

1.安装node,node -v 查看安装结果
sudo yum -y install nodejs npm
ndoe -v

在这里插入图片描述

2.安装json-server,json-server -h 查看安装结果
npm install json-server -g
json-server -h

阿里云centos部署jsonserver_第1张图片

3.上传 jsonserver所需的db.json文件
4.配置nginx代理

注意:此处需要确保阿里云控制台和服务器的5000端口正常开启
控制台:添加入方向的安全组策略
服务器:

# 防火墙放行5000端口
firewall-cmd --zone=public --add-port=5000/tcp --permanent 
# 重启防火墙
firewall-cmd --reload

配置 nginx

vim /usr/local/nginx/conf/nginx.conf

location /api {
    rewrite /api/(.*) /$1 break;
    proxy_pass http://localhost:5000;
}
5.安装pm2(解决jsonserver需要一直处于开启状态)
npm install pm2 -g

创建 process.json 文件

vim process.json

内容如下
args 中需要提供 jsonserver 使用的json文件的地址

{
  "apps": [
    {
      "name": "xxx-api",
      "script": "json-server",
      "args": "--watch /xx/xxx/db.json --port 5000"
    }
  ]
}

process.json 目录下运行 pm2,然后就可以在浏览器访问 jsonserver 提供的接口了

pm2 start process.json

pm2 常用命令

重启进程/应用

pm2 restart name

重启所有的进程/应用

pm2 restart all

查看所有的进程/应用

pm2 list

结束进程/应用,写id或者name

pm2 stop id/name

结束所有的进程/应用

pm2 stop all

删除进程/应用

pm2 delete name

删除所有的进程/应用

pm2 delete all

你可能感兴趣的:(阿里云,阿里云)