Я последовал за этот учебник чтобы создать простое приложение node.js на моем CentOS:
версия node.js:
$ node -v
v0.10.28
Вот мой app.js
:
// Include http module,
var http = require("http"),
// And url module, which is very helpful in parsing request parameters.
url = require("url");
// show message at console
console.log('Node.js app is running.');
// Create the server.
http.createServer(function (request, response) {
request.resume();
// Attach listener on end event.
request.on("end", function () {
// Parse the request for arguments and store them in _get variable.
// This function parses the url from request and returns object representation.
var _get = url.parse(request.url, true).query;
// Write headers to the response.
response.writeHead(200, {
'Content-Type': 'text/plain'
});
// Send data and end response.
response.end('Here is your data: ' + _get['data']);
});
// Listen on the 8080 port.
}).listen(8080);
Однако, когда я загрузил это приложение на свой удаленный сервер (предположим, что это адрес 123.45.67.89), я не смог получить к нему доступ в моем браузере.
http://123.45.67.89:8080/?data=123
Браузер вернул Error code: ERR_CONNECTION_TIMED_OUT
.
Я пробовал тот же код app.js, который отлично работает на моем локальном компьютере, что-то мне не хватает?
Я пытался ping
сервер и его адрес были доступны.
Спасибо.
Я собираюсь предположить, что вы не открывали свой брандмауэр для порта 8080. Вы можете сделать это с помощью iptables команда
iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
Если это сработает, вы можете сохранить состояние брандмауэра с помощью
service iptables save