0.0.0.0
我正在运行一个绑定到端口的Rails Web 应用服务器,80
如下所示:
sudo rails s --port=80 --bind=0.0.0.0
我可以通过我的私有地址访问它http://192.168.0.13/
,通常我可以通过环回地址http://127.0.0.1
/访问http://localhost
。但是由于某种原因,环回地址没有指向这个私有地址。我认为这个问题与我机器上配置的虚拟机有关,因为这个问题在我设置虚拟机后开始发生。
vagrant VM 设置(我没有配置)正在运行第二个 Web 应用服务器,我能访问http://127.0.0.1
。但是,即使我关闭了这个 vagrant VM,我仍然无法通过环回地址访问上面提到的 rails web 应用服务器。
vagrant VM 正在做什么来配置其自身的环回?
如何配置环回地址指向的私有地址?
ifconfig
如果有帮助的话,这是我的:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 4c:8d:79:d7:a9:e4
inet6 fe80::4e8d:79ff:fed7:a9e4%en1 prefixlen 64 scopeid 0x4
inet 192.168.0.13 netmask 0xffffff00 broadcast 192.168.0.255
nd6 options=1<PERFORMNUD>
media: autoselect
status: active
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether a8:20:66:5a:9b:c7
nd6 options=1<PERFORMNUD>
media: autoselect (none)
status: inactive
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
lladdr 10:dd:b1:ff:fe:4f:ee:4c
nd6 options=1<PERFORMNUD>
media: autoselect <full-duplex>
status: inactive
en2: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether d2:00:14:fe:e4:c0
media: autoselect <full-duplex>
status: inactive
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
ether 0e:8d:79:d7:a9:e4
media: autoselect
status: inactive
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
ether de:fa:c4:c2:1b:f7
inet6 fe80::dcfa:c4ff:fec2:1bf7%awdl0 prefixlen 64 scopeid 0x9
nd6 options=1<PERFORMNUD>
media: autoselect
status: active
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 4e:8d:79:7d:7e:00
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 7 priority 0 path cost 0
nd6 options=1<PERFORMNUD>
media: <unknown type>
status: inactive
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
inet 172.28.128.1 netmask 0xffffff00 broadcast 172.28.128.255
我看到Vagrantfile
它已经配置了一些端口转发:
system('sudo pfctl -E')
system('echo "
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 9080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 9443
" | sudo pfctl -f - > /dev/null 2>&1; echo "==> Fowarding Ports: 80 -> 9080, 443 -> 9443"')
答案1
127.0.0.1
是您的环回。它始终位于您所在机器的本地。创建虚拟机意味着它是一台新机器,并且它有自己的内部127.0.0.1
。您可以创建 50 个虚拟机,每个虚拟机都有自己的内部127.0.0.1
,并且计算机无法知道您想要哪一个。因此,您只能通过可路由 IP 地址访问虚拟机上的网页,而不能访问127.0.0.1
。