cPanel(Apache)上的Phusion乘客“无法获取” (表现);相同的代码适用于localhost和Heroku [英] Phusion Passenger on cPanel (Apache) "Cannot GET" (Express); the same code works on localhost and Heroku

查看:73
本文介绍了cPanel(Apache)上的Phusion乘客“无法获取” (表现);相同的代码适用于localhost和Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Nodejs应用在localhost&上运行良好Heroku,但在使用Phusion Passenger(CloudLinux)的cPanel托管上失败。

My Nodejs app works well on localhost & Heroku, but fails on my cPanel hosting with Phusion Passenger (CloudLinux).

当我在node_modules文件夹中查看时,Express在那里。

When I look in the node_modules folder, express is there.

这是浏览器中的样子: http://futuristicon.com/w2/

This is what it looks like in the browser: http://futuristicon.com/w2/

如果标题太笼统,我深表歉意。当有人告诉我问题出在哪里时,我会解决这个问题。有人知道如何启动和运行我的应用吗?

I apologize if the title is too general - I will fix it when someone tells me what the issue really is. Does anyone know how to get my app up and running?

这是错误日志:

App 1268608 output: internal/modules/cjs/loader.js:775
App 1268608 output:     throw err;
App 1268608 output:     ^
App 1268608 output: 
App 1268608 output: Error: Cannot find module 'express'
App 1268608 output: Require stack:
App 1268608 output: - /home/futur/w2/server.js
App 1268608 output: - /opt/passenger-5.3.7-9.el7.cloudlinux/src/helper-scripts/node-loader.js
App 1268608 output:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
App 1268608 output:     at Function.Module._load (internal/modules/cjs/loader.js:677:27)
App 1268608 output:     at Module.require (internal/modules/cjs/loader.js:830:19)
App 1268608 output:     at Module.require (/opt/passenger-5.3.7-9.el7.cloudlinux/src/helper-scripts/node-loader.js:80:25)
App 1268608 output:     at require (internal/modules/cjs/helpers.js:68:18)
App 1268608 output:     at Object.<anonymous> (/home/futur/w2/server.js:1:17)
App 1268608 output:     at Module._compile (internal/modules/cjs/loader.js:936:30)
App 1268608 output:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
App 1268608 output:     at Module.load (internal/modules/cjs/loader.js:790:32)
App 1268608 output:     at Function.Module._load (internal/modules/cjs/loader.js:703:12) {
App 1268608 output:   code: 'MODULE_NOT_FOUND',
App 1268608 output:   requireStack: [
App 1268608 output:     '/home/futur/w2/server.js',
App 1268608 output:     '/opt/passenger-5.3.7-9.el7.cloudlinux/src/helper-scripts/node-loader.js'
App 1268608 output:   ]
App 1268608 output: }
App 1271723 output: app is running on port 3002
App 1400344 output: app is running on port 3002 ```


推荐答案

我解决了这个问题-Phusion Passenger的问题是根路径不是'/',而是'/ yourAppURL'(在我的c语言中ase'/ w2'( https://futuristicon.com/w2/ )。

I solved the issue - the problem with Phusion Passenger is that the root path isn't '/', it's '/yourAppURL' (in my case '/w2' (https://futuristicon.com/w2/).

真的很奇怪,因为root在所有其他环境中都是'/'(正如我在问题中提到的那样-应用程序在Heroku&

Really weird, since root is '/' with all other environments (as I mentioned in the question - app worked flawlessly on Heroku & localhost env).

重要:除root以外的其他路由将无法使用。出于某种原因,您将不得不在.htaccess所在的文件夹内手动创建一个与route参数相同名称的空文件夹。

Important: routes others than root won't work out of the box. You will have to, for some reason, manually create an empty folder named the same as your route parameter, inside the folder in which your .htaccess lives.

例如,如果您想创建这样的路线:

For example, if you wanted to make a route like this:

app.get('/w2/signup', (req, res) => {
res.send('Signup!')
})  

您必须创建一个名为signup的新文件夹(不是应用程序根文件夹,而是应用程序URL的文件夹)

You would have to create a new folder named signup (not the application root folder, but the folder of your app's URL)

这篇关于cPanel(Apache)上的Phusion乘客“无法获取” (表现);相同的代码适用于localhost和Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆