【问题标题】:How to start directus using pm2?如何使用 pm2 启动 directus?
【发布时间】:2021-02-11 11:43:06
【问题描述】:

文档说:

除了使用 pm2 start hello.js 启动应用程序,您还可以启动 Directus 使用 pm2 start npm -- start

pm2 start npm -- start

我试过了

pm2 start npm /home/user/my-app/node_modules/.bin/directus start

https://docs.directus.io/guides/installation/ubuntu/

【问题讨论】:

    标签: pm2 directus


    【解决方案1】:

    您可以将启动脚本添加到您的 package.json 文件中

    "scripts": {                                                   
      "test": "echo \"Error: no test specified\" && exit 1",       
      "start": "directus start"                                    
    },  
    

    然后使用pm2 start npm -- start启动它

    【讨论】:

      【解决方案2】:

      文档没有错,如果您没有任何其他网站或正在使用 apache 或 Nginx 的虚拟主机,那就这么简单。

      就我而言,我两者都做。我有多个具有多个域的站点,其中一些通过使用虚拟主机来使用子域。

      如果您遇到类似情况,以下是一些提示:

      1. 在防火墙中打开正确的端口,directus默认使用8055。 sudo ufw allow 8055
      2. 对您的 Web 服务器使用端口转发。链接:https://www.ionos.com/digitalguide/websites/web-development/nodejs-for-a-website-with-apache-on-ubuntu/
      3. 将您的(子)域添加到您的 /etc/hosts 文件中。跑 sudo nano /etc/hosts/ 和以下行 127.0.0.1 ${{domain here}}

      我还建议阅读 pm2 文档以更好地理解它。

      【讨论】:

        【解决方案3】:

        如果您需要特定配置,pm2 start npm --start 将不够。您将需要一个 pm2 配置文件。

        1. 在您的directus 根目录中创建ecosystem.config.js 文件
        2. 将此内容添加到文件中:
        module.exports = {
          apps : [
            {
              name: "directus-app",
              script: "npx",
              args: "directus start",
              restart_delay: 500
            }
          ]
        }
        
        1. 使用您的首选配置编辑文件

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2023-03-10
          • 2016-12-10
          • 2018-02-17
          • 1970-01-01
          • 1970-01-01
          • 2019-10-30
          • 1970-01-01
          相关资源
          最近更新 更多