bug*_*yci 7 virtualbox vagrant
我使用下面给出的Vagrantfile设置为virtualbox配置了vagrant.我可以从主机(HM)连接到虚拟机上运行的Web服务器.
我也可以从网络机器ping服务器,但当我尝试从网络访问Web服务器时,虚拟机(VM)获取请求并说它响应(apache),但网络机器(NM)没有得到回应.
如何配置vagrant或virtualbox从NM访问?我尝试在VM接口文件上将eth1更改为eth0,但它没有用.Vagrant无法放松机器.
提前致谢
Vagrantfile:
config.vm.define "web" do |web|
web.vm.box = "raring"
web.vm.network "public_network", ip: "192.168.0.53", bridge: 'eth0'
web.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", 1024]
end
end
Run Code Online (Sandbox Code Playgroud)
主机界面
eth0 Link encap:Ethernet HWaddr 54:04:a6:68:7d:85
inet addr:192.168.0.102 Bcast:255.255.255.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:576 Metric:1
RX packets:142100 errors:0 dropped:0 overruns:0 frame:0
TX packets:110704 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:61653460 (61.6 MB) TX bytes:14976111 (14.9 MB)
Interrupt:55 Base address:0xa000
Run Code Online (Sandbox Code Playgroud)
虚拟机界面
eth0 Link encap:Ethernet HWaddr 08:00:27:49:4c:f1
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe49:4cf1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:386 errors:0 dropped:0 overruns:0 frame:0
TX packets:276 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41117 (41.1 KB) TX bytes:36296 (36.2 KB)
eth1 Link encap:Ethernet HWaddr 08:00:27:c3:16:90
inet addr:192.168.0.53 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fec3:1690/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:946 errors:0 dropped:0 overruns:0 frame:0
TX packets:1017 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:116117 (116.1 KB) TX bytes:90515 (90.5 KB)
Run Code Online (Sandbox Code Playgroud)
虚拟机/ etc/network/interfaces文件:
# The primary network interface
auto eth0
iface eth0 inet dhcp
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
address 192.168.0.53
netmask 255.255.255.0
#VAGRANT-END
Run Code Online (Sandbox Code Playgroud)
VM上的apache响应:
192.168.0.100 - - [16/Nov/2013:10:39:10 +0000] "GET / HTTP/1.1" "curl/7.32.0" 200 7466 6005
Run Code Online (Sandbox Code Playgroud)
这个问题不是由 vagrant 或 vagrant 设置引起的,而是由于虚拟机 (VM) 中的 apache 配置错误造成的。
在虚拟机中修改您的 apache 站点配置:
vim /etc/apache2/sites-enabled/yours_site_config.conf
将服务器名称更改为:ServerName 192.168.0.53
重新启动 apache 后,检查浏览器中的结果。
例如:
<VirtualHost *:80>
ServerAdmin servers@localhost
ServerName 192.168.0.53
DocumentRoot /var/www
</VirtualHost>
192.168.0.53 - 这是您的虚拟机的 inet 地址。
归档时间: |
|
查看次数: |
2046 次 |
最近记录: |