Strapi部署到nginx服务器
工具
服务器 Linux version 4.18.0-305.3.1.el8.x86_64
nginx 1.14.1
strapi v3.6.0-beta.0
node v16.13.0
数据库 用的strapi默认的sqlite
FileZilla
Xshell
域名一个
创建Strapi项目
直接看我老文章,按步骤来即可
Strapi新手入门教程
启动文件
在你strapi项目的根目录下新建server.js
const strapi = require('strapi');
strapi().start();
上传项目到服务器
- 用FileZilla软件上传Strapi项目到服务器。上传除git、build、cache、node_modules外所有文件,大概30MB左右。(整个项目500M,不要直接全部传)
- 用Xshell登录服务器并cd到strapi项目根目录,运行
npm i安装依赖,然后npm run build生成控制台页面。
用pm2启动项目
npm install -g pm2
pm2 -v
// 5.1.2
// cd 到strapi项目根目录下执行
pm2 start ./server.js

如果不使用nginx,直接访问strapi
访问 http://你服务器ip:1337/admin
如果不通
1:排查服务器1337端口是否开放。
2:输入pm2 list,查看server的status是否online
安装nginx
配置nginx.conf
在nginx配置反向代理
没有域名就填localhost,然后用ip访问也可以。
server {
listen 80;
server_name 你的域名.com;
location / {
proxy_pass http://127.0.0.1:1337;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
启动nginx
启动nginx方法
打开浏览器,访问http://你的域名.com/admin或者 https://你的域名.com/admin
