我在端口80上运行一个绑定到0.0.0.0的rails web应用服务器,如下所示:
sudo rails s --port=80 --bind=0.0.0.0
我可以在我的私人地址http://192.168.0.13/访问它,通常我可以在回送地址http://127.0.0.1 / http://localhost 。 但是由于某些原因,回送地址并不指向这个专用地址。 我认为这个问题与我的机器上configuration的虚拟机有关,因为在安装虚拟机之后,这个问题就开始发生了。
stream浪的虚拟机设置(我没有configuration)运行第二个Web应用服务器,我可以在http://127.0.0.1访问。 但是,即使当我closures这个stream浪VM,我仍然无法访问上面提到的在回环地址这个rails web应用服务器。
什么是stream浪虚拟机做configuration到自己的回环?
如何configuration环回地址指向的私有地址?
这是我的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我看到它已经configuration了一些端口转发:
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"')
127.0.0.1是你的回环。 您所在的机器始终位于本地。 创build虚拟机意味着它是一个新的机器,它有自己的内部127.0.0.1 。 你可以创build50个虚拟机,每个虚拟机都有自己的内部127.0.0.1 ,计算机无法知道你想要的是哪一个。 所以你应该只能通过可路由的IP地址访问虚拟机上的网页,而不是127.0.0.1 。