I'm trying to set up a simple "Hello world" node.js app.

我正在尝试建立一个简单的“Hello world”节点。js应用。

I've created the following index.js file:

我创建了以下索引。js文件:

var app = require("express")();
var http = require("http").Server(app);

app.get("/", function(req, res){
    res.send("<h1>Hello worlddddd</h1>");
});

http.listen(8080, function(){
    console.log("listening on *:8080");
});

When I open up my local console, and perform node index.js, I get the message "listening on *:8080", as expected. I point my browser to localhost:8080, and I see the HTML page saying "Hello worlddd", as desired.

当我打开本地控制台并执行节点索引时。js,我得到的信息是“听*:8080”,正如所料。我将浏览器指向localhost:8080,我看到HTML页面显示“Hello worlddd”,这是我想要的。

Now, I'm trying to do the same on my Virtual Private Server, so I can access the same app from different computers, but all I get is connection timeouts. I've followed these steps:

现在,我尝试在我的虚拟私有服务器上执行相同的操作,这样我就可以从不同的计算机访问相同的应用程序,但是我得到的只是连接超时。我跟着这些步骤:

  • Install node.js on my VPS
  • 安装节点。js在我的VPS
  • Install express via npm install --save express@4.10.2
  • 通过npm安装安装express -save express@4.10.2。
  • Upload my index.js file to the var/www/html folder on my server with IP 192.123.123.12 (an example, this isn't my real IP).
  • 上传我的索引。我的服务器上的var/www/html文件夹的js文件,带有IP 192.123.123.12(一个例子,这不是我真正的IP)。
  • Access the server via PuTTY, and run node index.js, where I get "listening on *:8080", so I know node.js is working.
  • 通过PuTTY访问服务器,并运行节点索引。这里有"监听*:8080",所以我知道node。js是有效的。
  • Now I point my browser to http://192.123.123.12:8080 and after about 20 seconds, I get the browser error: "The connection has timed out".
  • 现在,我将浏览器指向http://192.123.123.12:8080,在大约20秒后,我得到了浏览器错误:“连接超时了”。
  • I've tried listening to port :80 instead, but I get the error that this port is already in use.
  • 我尝试了监听端口:80,但是我得到了这个端口已经在使用的错误。

Does anybody know what I'm doing wrong? Am I using the wrong port? Am I pointing to the wrong URL? Do I need to modify my server preferences? (running Apache on CentOS). I've only found dozens of tutorials that teach you how to run a node.js app on your local computer(pointing the browser at localhost:8080), but I need it to run on my remote server so multiple computers can access the same app.

有人知道我做错了什么吗?我用错端口了吗?我指向错误的URL了吗?我需要修改我的服务器首选项吗?(在CentOS运行Apache)。我只找到了几十个教程教你如何运行节点。本地计算机上的js应用程序(将浏览器指向localhost:8080),但我需要它在我的远程服务器上运行,以便多台计算机可以访问同一个应用程序。

1 个解决方案

#1


4

The issue is that your current filters (iptables) block traffic unless you explicitly allow it.

问题是,除非显式地允许,否则当前的过滤器(iptables)会阻塞流量。

You just need to open port TCP 8080 inbound, and you should be able to reach your node.js server!

您只需打开TCP 8080入站端口,就可以到达您的节点。js服务器!

更多相关文章

  1. contains和compareDocumentPosition 方法来确定是否HTML节点间的
  2. js之DOM操作(访问父节点parentNode)
  3. 如何使用客户端Javascript数组并通过节点发布。将js API插入Mong
  4. 是否可以从节点js中的同一模块导出构造函数和一些正常函数?
  5. Python学习之——Tcp/ip基础/IP地址/DNS/端口简介
  6. python打印系统所有tcp,udp监听端口及服务
  7. 迭代地在python中编写XML节点
  8. django npm和节点包体系结构
  9. 使用Python编写简单的端口扫描器的实例分享【转】

随机推荐

  1. 布局(1、线性布局)
  2. ListPreference
  3. 不停地切换两张图片ViewFlipper
  4. 2.6.2 Notification的功能与用法
  5. Android中的时间日期选择器
  6. Android(安卓)添加系统服务的方法
  7. 2.5.2 使用alertdialog 创建列表对话框
  8. ViewFlipper+GestureDetector实现不循环
  9. Android RelativeLayout相对布局属性简析
  10. 2.6.1 使用toast显示提示信息框