我在Windows 7主机上的Vagrant的Virtualbox中安装了Ubuntu Server 16.04.1 Xenial Xerus(32位)。Vagrantfile的内容是
Vagrant.configure("2") do |config|
config.vm.box = "boxcutter/ubuntu1604-i386"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.hostname = "vagrant.templavoilaplus"
config.vm.network "private_network", ip: "192.168.33.148"
config.vm.synced_folder "E:/xampp/htdocs/github/templavoilaplus/", "/var/www/templavoilaplus/public_html"
config.vm.provision "shell", path: "setup_for_ubuntu_box.sh"
end
在运行中无所事事时,显示为
E:\Virtual Machines\vagrant>vagrant up
==> default: Checking if box 'boxcutter/ubuntu1604-i386' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 (guest) => 8080 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
==> default: Machine booted and ready!
[default] GuestAdditions seems to be installed (5.1.22) correctly, but not
runni
ng.
: Inappropriate ioctl for device
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => E:/Virtual Machines/vagrant
default: /var/www/templavoilaplus/public_html =>
E:/xampp/htdocs/github/templavoilaplus
==> default: Machine already provisioned. Run `vagrant provision` or use the
`--
provision`
==> default: flag to force provisioning. Provisioners marked to run always will
still run.
E:\Virtual Machines\vagrant>
Windows主机文件的内容是
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
216.98.48.18 127.0.0.1
216.98.48.53 127.0.0.1
216.98.48.57 127.0.0.1
216.98.48.133 127.0.0.1
216.98.48.134 127.0.0.1
#adaugat 28/5/2017 pentru vhost xampp github
127.0.0.1 localhost
127.0.0.1 github.localhost
#adaugat 2/6/2017 pentru vagrant private network
192.168.33.148 vagrant.templavoilaplus
我在虚拟机上提供了apache2和php模块(通过shell脚本),并通过将000-default.conf复制并修改为templavoilaplus.conf来创建了虚拟主机。该文件的内容是
<VirtualHost *:80>
ServerAdmin alex@google.com
ServerName vagrant.templavoilaplus
DocumentRoot /var/www/templavoilaplus/public_html
ErrorLog ${APACHE_LOG_DIR}/templavoilaplus_error.log
CustomLog ${APACHE_LOG_DIR}/templavoilaplus_access.log combined
</VirtualHost>
在public_html文件夹中安装了主机的文件夹。之后,我运行了a2ensite并重新加载了Apache。/ etc / host的内容是
127.0.0.1 vagrant
127.0.0.1 localhost
127.0.0.1 vagrant
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
##vagrant-hostmanager-start
192.168.33.148 vagrant.templavoilaplus
##vagrant-hostmanager-end
如果我在主机中打开浏览器并输入192.168.33.148,则会得到Apache2 Ubuntu默认页面(成功),而且,如果我在主机中ping
ping vagrant.templavoilaplus
结果是
Ping statistics for 192.168.33.148:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 2ms, Average = 2ms
如果我在来宾中ping(通过腻子)
ping vagrant.templavoilaplus
它显示类似的内容(192.168.33.148)。
问题是这样的:如果我在主机的浏览器地址栏中键入
vagrant.templavoilaplus
我得到的是空白页(mozilla)或Google搜索结果(chrome)。页面index.php(在虚拟主机重定向之后)应显示“成功”。