Namecheap:节点JS Express应用程序-未找到应用程序路线返回404 [英] Namecheap: Node JS Express App - App Route return 404 not found

查看:157
本文介绍了Namecheap:节点JS Express应用程序-未找到应用程序路线返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用NameCheap共享主机启动Simple Express应用程序.

Trying to get Simple Express Application up using NameCheap Shared Hosting.

我已经按照此处的说明设置了Node JS应用程序

I have set up my Node JS application as Described here NodeJS NameCheap Docs

当前设置:

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

我已经使用提供的按钮运行了NPM安装

I have ran NPM Install using the button provided

我尝试加载URL http://url.com/hello,期望Hello World显示在页面中.

I have tried loading the URL http://url.com/hello Expecting Hello World to displayed in the Page.

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"))
);

导航到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仅告诉您如何配置Node.js应用,但是其托管基于cPanel,这需要您配置Web服务器(通常为Apache).一旦您运行了应用程序,就会有一个特殊的按钮将其注册为apache配置,也可以从您的域中运行它.我不知道具体的步骤,但您应该要求NC支持将您定向到他们的文档,以配置apache来运行您配置的nodejs应用. 如果他们没有从知识库中链接文章,请使用此链接:

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). 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. 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. 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. 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. To make sure you are reading the correct document check in namecheap cpanel for the docs button and review all the above. It should be obvious what needs configured - your nodejs code is probably not the cause here

这篇关于Namecheap:节点JS Express应用程序-未找到应用程序路线返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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