簡體   English   中英

在vagrant的centos上運行Node.js服務器

[英]Running Node.js server on centos on vagrant

我想在虛擬機中運行Node.js服務器。

我執行了vagrant upnode Server.js
然后,我從主機瀏覽器訪問了http://192.168.33.10:1337/
但是,瀏覽器輸出ERR_EMPTY_RESPONSE
我如何解決它?

流浪文件

Vagrant.configure(2) do |config|
  config.vm.box = "centos"
  config.vm.network "private_network", ip: "192.168.33.10"
end

Server.js

var http = require('http');

http.createServer(function(request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');
}).listen(1337, "192.168.33.10");

console.log('server running');
  1. 確保框已綁定到正確的地址,如@frederic所述。
  2. 確保它不是防火牆:sudo service iptables stop
  3. 確保您的主機(您的計算機)可以訪問無所事事的VM。 3a。 如果橋接,請使用VM 3b的內部IP。 如果將端口轉發到VM(config.vm.network“ forwarded_port”,guest虛擬機:80,主機:8080),請從主機(您的計算機)使用http:// localhost:8080

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM