通常我们使用“strapi start”来启动strapi。
我将它托管在 AWS ubuntu 上:
尝试“启动strapi&”在后台运行它。但是,一旦终端关闭,我们就无法再访问strapi 控制台了。
通常我们使用“strapi start”来启动strapi。
我将它托管在 AWS ubuntu 上:
尝试“启动strapi&”在后台运行它。但是,一旦终端关闭,我们就无法再访问strapi 控制台了。
script not found: server.js
使用@user1872384 的解决方案时出现错误。所以,这里是在后台模式下运行strapi的正确方法。
NODE_ENV=production pm2 start --name APP_NAME npm -- start
这只会告诉 pm2 使用npm start
命令并让 npm 来做这which script to run
部分。
希望它可以帮助某人。
要在开发模式下运行strapi,请使用项目文件夹中的以下 pm2 命令。
pm2 start npm --name my-project -- run develop
和
pm2 list
查看状态
需要使用pm2:
开始:
npm install pm2 -g
NODE_ENV=production pm2 start server.js --name api
列出所有进程:
pm2 list
┌──────────┬────┬──────────┬──────┬────────┬──────── ┬──────────┬────────┬──────┬────────────┬────────┬── ────────┐</p>
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watch │</p>
├──────────┼────┼──────────┼──────┼────────┼──────── ┼────────┼────────┼──────┼────────────┼────────┼── ────────┤</p>
│ api │ 0 │ 0.1.0 │ fork │ 21817 │ 在线 │ 0 │ 2m │ 0% │ 108.0 MB │ ubuntu │ 禁用 │</p>
└──────────┴────┴──────────┴──────┴────────┴──────── ┴──────────┴────────┴──────┴────────────┴────────┴── ────────┘</p>
要停止,请使用 id:
pm2 stop 0
第一的
npm install pm2 -g
将 server.js 添加到项目的根目录并写入以下行:
const strapi = require('strapi');
strapi().start();
然后保存
pm2 start server.js
我们也可以按类型从 pm2 开始
pm2 开始“纱线开发”
最好的方法是使用pm2及其生态系统.config.js文件。
npm i -g pm2@latest
module.exports = {
apps: [
{
name: 'give-your-app-a-name',
script: 'npm',
args: 'start',
watch: true, // automatically restart the server for file changes
max_memory_restart: '450M',
env: {
NODE_ENV: 'production',
},
},
{
name: 'give-your-another-app-a-name',
script: 'npm',
args: 'start',
env: {
NODE_ENV: 'production',
},
},
],
}
pm2 start ecosystem.config.js
就是这样。
这是关于使用 PM2 启动 Strapi的官方页面。
从strapi命令开始
默认情况下有两个重要的命令。
yarn develop
以开发模式启动您的项目。
yarn start
启动您的应用程序进行生产。
您还可以使用 yarn start 或 develop 命令启动您的流程管理器。
pm2 start npm --name my-app -- run develop
pm2 start npm --name my-app -- run develop