I'm trying to set up a simple "Hello world" node.js app.
I've created the following index.js file:
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.
Now, I'm trying to do the same on my Virtual Private Server, so I can access the same app from different puters, but all I get is connection timeouts. I've followed these steps:
- Install node.js on my VPS
- Install express via
npm install --save [email protected]
- 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). - Access the server via PuTTY, and run
node index.js
, where I get"listening on *:8080"
, so I know node.js is working. - 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". - I've tried listening to port :80 instead, but I get the error that this port is already in use.
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 puter(pointing the browser at localhost:8080), but I need it to run on my remote server so multiple puters can access the same app.
I'm trying to set up a simple "Hello world" node.js app.
I've created the following index.js file:
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.
Now, I'm trying to do the same on my Virtual Private Server, so I can access the same app from different puters, but all I get is connection timeouts. I've followed these steps:
- Install node.js on my VPS
- Install express via
npm install --save [email protected]
- 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). - Access the server via PuTTY, and run
node index.js
, where I get"listening on *:8080"
, so I know node.js is working. - 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". - I've tried listening to port :80 instead, but I get the error that this port is already in use.
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 puter(pointing the browser at localhost:8080), but I need it to run on my remote server so multiple puters can access the same app.
Share Improve this question asked Feb 25, 2016 at 23:34 M -M - 28.6k12 gold badges54 silver badges93 bronze badges 11- 1 You need to find specific documentation for running a node.js server app on your VPS and how to configure the ining port and whether long running servers (like nodejs) are supported. This is not generic instructions, but likely involves specific configuration for your own hosting service. – jfriend00 Commented Feb 25, 2016 at 23:46
- Oh, thanks! So it's not expected to work straight out of the box, then? Maybe my hosting provider's customer care center can help out. – M - Commented Feb 25, 2016 at 23:48
- There may be simply some (default) filtering going that prevents connections to other ports that the predefined ones. Or if you share the IP with other hosts, it might be quite a bit more plex. – jcaron Commented Feb 25, 2016 at 23:49
- 2 Check for filters (probably iptables if it's some kind of Linux-based server). If you have any kind of control panel, it's probably configurable somewhere in there. – jcaron Commented Feb 26, 2016 at 1:21
-
1
@jcaron OH MY GOSH, I GOT IT! Thanks so much! iptables definitely sent me in the right direction, since it's an Apache CentOS server. I ended up using the following mand:
sudo iptables -I INPUT 1 -i + -p tcp --dport 8080 -j ACCEPT
. Does using the wildcard+
make me vulnerable to any security issues? I still don't fully understand what that interface parameter does, despite reading the Ubuntu Iptables Howto page. – M - Commented Feb 26, 2016 at 2:28
1 Answer
Reset to default 4The issue is that your current filters (iptables) block traffic unless you explicitly allow it.
You just need to open port TCP 8080 inbound, and you should be able to reach your node.js server!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745433051a4627480.html
评论列表(0条)