gpt4 book ai didi

connection - Vagrant 拒绝以 private_network 模式连接

转载 作者:行者123 更新时间:2023-12-04 07:24:17 26 4
gpt4 key购买 nike

关闭。这个问题是 off-topic 。它目前不接受答案。












想改善这个问题吗? Update the question 所以它是堆栈溢出的 on-topic

8年前关闭。




Improve this question




我已将运行 VistualBox 的 Vagrant (1.2.2) VM 设置为 :private_network 并且我已经在其上启动了 Sinatra 服务器。但是我无法连接到该 Sinatra 实例。但是,VM 会运行并响应 ping。

这是我的 Vagrantfile

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

所以我启动 Vagrant VM 并通过 ssh 进入它
prodserv$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant

prodserv$ vagrant ssh
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-23-generic x86_64)

* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Thu May 23 14:01:05 2013 from 10.0.2.2

所以到这里一切都很好。
对 VM 的 ping 可以正常工作(我还检查了这确实是 VM ip。因此在没有 vagrant up 的情况下 ping 将导致包丢失)
prodserv$ ping 192.168.33.10
PING 192.168.33.10 (192.168.33.10): 56 data bytes
64 bytes from 192.168.33.10: icmp_seq=0 ttl=64 time=0.543 ms
64 bytes from 192.168.33.10: icmp_seq=1 ttl=64 time=0.328 ms

伟大的!现在我在虚拟机上启动服务器
vagrant@precise64:~$ sudo ruby /vagrant/server.rb
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:4567, CTRL+C to stop

这是对应的 server.rb
require 'rubygems'
require 'sinatra'

get '/' do
puts "WOW!"
'Hello, world!'
end

如果我 curl 现在从 guest VM 到 Sinatra 一切正常,“你好,世界!”将被退回。
vagrant@precise64:~$ curl 'http://localhost:4567'
Hello, world!vagrant@precise64:~$

#and the Sintra/Ruby process gets me this
WOW!
127.0.0.1 - - [23/May/2013 16:06:36] "GET / HTTP/1.1" 200 13 0.0026

但是,如果我尝试从 主机 curl 主机 连接被拒绝。
prodserv$ curl -v 'http://192.168.33.10:4567'
* About to connect() to 192.168.33.10 port 4567 (#0)
* Trying 192.168.33.10...
* Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

那么这是什么一回事?

最佳答案

您的 sinatra 正在监听 localhost:4567,而不是 0.0.0.0,因此它仅适用于 localhost。

关于connection - Vagrant 拒绝以 private_network 模式连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16718970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com