我有一個簡單的node http server
在vagrant
虛擬機上運行。我想用我的本地機器上的瀏覽器解決它。連接到運行在流浪機上的節點js服務器
varhttp=require("http");
http.createServer(function(request,response){
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(3000);
這是我Vagrantfile:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provision "shell", path: "config.sh"
end
我無法弄清楚如何從我的瀏覽器解決這個問題。
每當我在流浪VM中做curl localhost:3000
,我得到Hello world
消息。
從我的本地機器上,每當我嘗試打開localhost:8080
時,我會收到This site can’t be reached
,如Vagrant forwarding中所建議的。
你已經從字面上複製了轉發行而不理解它的作用?你需要轉發3000 –
@ cricket_007是的,我要求澄清,謝謝!現在我明白它是如何工作的。 –