简体   繁体   English

Namecheap:Node JS Express应用程序-未找到应用程序路由返回404

[英]Namecheap: Node JS Express App - App Route return 404 not found

Trying to get Simple Express Application up using NameCheap Shared Hosting. 尝试使用NameCheap共享主机启动Simple Express应用程序。

I have set up my Node JS application as Described here NodeJS NameCheap Docs 我已经按照此处所述设置了Node JS应用程序, NodeJS NameCheap Docs

Current Setup: 当前设置:

Application Root: url.com
Application URL: url.com
Application Startup File: server.js

I have ran NPM Install using the button provided 我已经使用提供的按钮运行了NPM安装

I have tried loading the URL http://url.com/hello Expecting Hello World to displayed in the Page. 我尝试加载URL http://url.com/hello希望“ Hello World显示在页面中。

var express = require("express");
var app = express();
const port = 3001;

app.set("port", port);

app.get("/hello", function(req, res) {
  res.send("hello world");
});

app.listen(app.get("port"), () =>
  console.log("Started listening on %s", app.get("port"))
);

The results I am getting when navigating to http://url.com/hello : 导航到http://url.com/hello时得到的结果:

Not Found
The requested URL /index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Namecheap only tells you how to configure the nodejs app however their hosting is based on cPanel which requires you configure the webserver (apache generally). Namecheap仅告诉您如何配置nodejs应用程序,但是它们的托管基于cPanel,这需要您配置Web服务器(通常为Apache)。 Once you get an application running there's a special button to register it for the apache configuration aka let it run from your domain. 一旦您使应用程序运行,就会有一个特殊的按钮来为apache配置注册它,也可以从您的域中运行它。 I don't know the steps by heart but you should ask NC support to direct you to their documentation for configuring apache to run a nodejs app you configured. 我不知道具体的步骤,但您应该要求NC支持将您定向到他们的文档,以配置apache以运行您配置的nodejs应用程序。 If they do not link an article from their knowledge base use this link: https://confluence1.cpanel.net/plugins/servlet/mobile?contentId=17190639#content/view/17190639 Basically what you need now is to configure cPanel or ssh into your server and test your app locally. 如果他们没有链接其知识库中的文章,请使用以下链接: https: //confluence1.cpanel.net/plugins/servlet/mobile?contentId=17190639#content/view/17190639现在,基本上,您需要配置cPanel或SSH到您的服务器并在本地测试您的应用程序。 There's a number of things that could cause your issues like incorrect apache configuration (your default port 80 is looking for php app), port not open/firewalled, application not registered - and all of this is cPanel specific. 有很多事情可能会导致您的问题,例如错误的apache配置(您的默认端口80正在寻找php应用程序),端口未打开/防火墙,应用程序未注册-所有这些都是cPanel特定的。 To make sure you are reading the correct document check in namecheap cpanel for the docs button and review all the above. 为了确保您阅读的文档正确,请在namecheap cpanel中找到docs按钮,然后检查以上所有内容。 It should be obvious what needs configured - your nodejs code is probably not the cause here 显然需要配置什么-您的nodejs代码可能不是这里的原因

In my case, it was the problem with .htaccess file. 就我而言,这是.htaccess文件的问题。 Adding the following rules in my .htaccess file present in the website's public directory helped me: 在网站公共目录中的.htaccess文件中添加以下规则对我有帮助:

# CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/<user>/<your_nodejs_app_folder>"
PassengerBaseURI "/."
PassengerNodejs "/home/<user>/nodevenv/<nodejs_app>/<version>/bin/node"
PassengerAppType node
PassengerStartupFile <startup_script>.js
# CLOUDLINUX PASSENGER CONFIGURATION END

Make the required changes in the above rules before pasting them in your .htaccess file. 在将以上规则粘贴到您的.htaccess文件之前,请对它们进行必要的更改。 Also, just in case, make sure the port you are using is open, via customer support. 另外,以防万一,请通过客户支持确保您使用的端口已打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM