localhost(127.0.0.1)与节点Web服务器上的远程服务器ip之间有何不同

时间:2018-05-09 05:33:59

标签: node.js ubuntu

我尝试用ubuntu服务器了解基于Web服务器的Node.js。我首先在主机变量中设置“localhost”,但是当我访问http://192.168.0.11:3000等远程服务器时,它不起作用。所以,我将变量数据更改为“192.168.0.11”。它正在使用浏览器。 我检查了本地桌面上的ubuntu防火墙,端口号,telnet。我能否知道IP addr的工作原理。

var http = require('http');
const host = '192.168.0.11';
// const host = 'localhost'; or '127.0.0.1';

http.createServer(function(req, res){
res.writeHead(200, {'Content-Type':'text/html'});
res.end('Hello world!');
}).listen(3000, host);

console.log('Server is running at',host,':3000');

0 个答案:

没有答案