Phusion Passenger:nodejs 应用程序出现“初始化语言运行时”和“加载或执行应用程序”错误

问题描述 投票:0回答:1

我的nodejs应用程序在开发环境中的本地计算机上运行良好,但是让它在生产服务器上运行是一场噩梦。

简而言之,应用程序正在启动,但内容未在网站上加载。如屏幕截图所示,它无法完全初始化。

Screenshot

有人对此有什么想法吗?即使托管公司也不确定是什么原因造成的,到目前为止我在谷歌上找不到任何相关内容。我只知道它来自 Phusion Passenger...

node.js passenger phusion
1个回答
0
投票

我会发布我的解决方案,以防其他人遇到这个问题。

如果您使用express 创建了一个nodejs 应用程序并使用express 生成器来设置该应用程序,您会注意到项目目录中bin 文件夹内的启动文件名为

www
。通常它被命名为
app.js

Phusion Passenger 寻找

app.js
来启动应用程序。您需要告诉 Phusion Passenger 在您的配置文件中查找
./bin/www
。对于不同的系统,它可能会有所不同。在 apache 中它位于这里:

/etc/apache2/conf.d/userdata/std/2_4/YOUR_USERNAME/YOUR_DOMAIN/YOUR_APPNAME.conf

您需要添加此启动文件行:

PassengerStartupFile ./bin/www

您的配置文件应如下所示:

<Location "/">
    <IfModule mod_passenger.c>
        PassengerAppEnv "development"
        PassengerEnabled on
        PassengerBaseURI "/"
        PassengerAppRoot "/home/YOUR_USERNAME/YOUR_DOMAIN"
        PassengerAppGroupName "YOUR_APP_NAME"
        PassengerRuby /opt/cpanel/ea-ruby27/root/usr/libexec/passenger-ruby27
        PassengerPython /usr/bin/python
        PassengerNodejs /opt/cpanel/ea-nodejs10/bin/node
        PassengerAppType node

        PassengerStartupFile ./bin/www
        
    </IfModule>
</Location>

然后你只需要保存文件,重建apache http配置文件并重新启动apache。

我使用WHM内的终端来运行这两行:

1#

/usr/local/cpanel/scripts/rebuildhttpdconf

2#

/usr/local/cpanel/scripts/restartsrv_httpd

组合#

/usr/local/cpanel/scripts/rebuildhttpdconf && /usr/local/cpanel/scripts/restartsrv_httpd

这篇文章中的说明可以在这里找到:

https://docs.cpanel.net/knowledge-base/web-services/how-to-install-a-node.js-application/

© www.soinside.com 2019 - 2024. All rights reserved.