[英]node.js 8080 port isn't listening
我在這里關注node.js教程,
http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/
這是代碼,
var sys = require("sys"),
http = require("http");
http.createServer(function(request, response) {
response.sendHeader(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.close();
}).listen(8080);
sys.puts("Server running at http://localhost:8080/");
在這里,它說像這樣的網址運行,
服務器的IP:8080 /
但是如果我這樣做,
它只是顯示,無法連接到該網址。
我在服務器上打開了8080端口。
==========================
我假設Codeigniter網址幫助程序搞砸了...
本教程可能使用了不正確或不建議使用的方法。 更換
response.sendHeader(200, {"Content-Type": "text/html"});
與
response.writeHead(200, {"Content-Type": "text/html"});
和
response.close();
與
response.end();
我同意“第三……”的回答,進行更改,如果是本地使用此URL
http://127.0.0.1:8080/
但
如果您不是在本地計算機上運行服務器,而是在諸如webserver(AWS)
類的webserver(AWS)
上運行服務器,則必須讓AWS防火牆的安全性允許該端口在Internet上公開,並且還要記住使用AWS實例URL
http://AWSinstanceURL:portno/
用這個
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('It Works!! Path Hit: ' + request.url);
}
//Create a server
var server = http.createServer(handleRequest);
//Lets start our server
server.listen(PORT, function(){
//Callback triggered when server is successfully listening. Hurray!
console.log("Server listening on: http://localhost:%s", PORT);
});
現在打開http:// localhost:8080 ,您會得到結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.