【问题标题】:What is the url with which I can access my expess app (nodejs)我可以访问我的快速应用程序(节点 js)的 url 是什么
【发布时间】:2019-05-25 11:30:11
【问题描述】:

我已经在 GoDaddy 上部署了我的 Nodejs Express 应用程序,使用 ssh 访问来配置整个事情。但我找不到指向我的应用的 URL。

它在我的电脑上完美运行,我通过链接http://localhost:3000访问应用程序

const express = require("express");
const bodyParser = require("body-parser");
const httpRequest = require("request");
const app = new express();
const http = require("http").Server(app);
const io = require("socket.io")(http);

app.set("view engine","ejs");

var port = process.env.PORT || 3000;


app.use(express.static("public"));

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
//headers
app.use(function (req, res, next) {

// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');

// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, 
PATCH, DELETE');

// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);

// Pass to next layer of middleware
next();
});

app.get("/",(request,response)=>{
 response.send("hello world!");
});


http.listen(port,function(){
 console.log(server.address());
 console.log("listening on port "+port);

});

我有我的服务器的域名,我认为在它的末尾添加“:3000”可以让我访问该应用程序,但显然它没有,我想知道如何访问它。

【问题讨论】:

  • 你的服务器操作系统是什么?是专用服务器吗?如果您的服务器是共享的,则 PORT 3000 或 env 中设置的任何端口。需要允许公共访问。您可以联系 GoDaddy 客户服务以启用该端口以供公众访问。

标签: node.js express url routing ip


【解决方案1】:

您可能必须先打开端口。你做这件事的方式取决于你使用什么,你可以用类似 Linux 的操作系统和 ufw 来做

sudo ufw 允许 3000

您可以在此处找到更多信息和文档:

ufw - Uncomplicated Firewall

【讨论】:

    【解决方案2】:

    使用您的 GoDaddy 虚拟机的 IP 地址。 按照以下说明找到它:

    1. 登录您的 GoDaddy 帐户。
    2. 在“我的产品”页面中,单击服务器。
    3. 在您要使用的服务器旁边,单击管理。服务器 IP 地址出现在
    4. 详细信息选项卡。您可能需要向下滚动才能看到列表中的地址。

    用途:

    http://youripaddress:3000
    

    【讨论】:

    • 我这样做了,但它不起作用,我仍然无法访问我的应用程序
    • 然后尝试如上所述打开端口。或确保它已打开:sudo ufw status
    • 当我执行 sudo 我得到:bash: sudo : command not found
    • 您使用哪种操作系统?
    • 顺便说一句,您可以在端口 80 上运行您的应用程序,它会工作。可以试试吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    相关资源
    最近更新 更多