采用如下域名:
development.mysite.com
我想使用 Vagrant 设置一个虚拟主机,这样我就可以在浏览器中访问此位置。
据我所知,它不会让我使用端口 80,所以即使我将主机文件更改为如下内容:
127.0.0.1 development.mysite.com
还是找不到。
有人有想法吗?
更新
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "hashicorp/precise32"
# Networking
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.network "private_network", ip: "192.168.33.10"
# Synced folders
config.vm.synced_folder ".", "/var/www"
# Provisioning
config.vm.provision :shell, :inline => "apt-get update --fix-missing"
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
(puppet module install example42/puppi; true)
(puppet module install example42/apache; true)
(puppet module install example42/php; true)
(puppet module install puppetlabs/stdlib; true)
(puppet module install puppetlabs/mysql; true)
(puppet module install saz/vim; true)"
end
config.vm.provision "puppet" do |puppet|
puppet.facter = {
"fqdn" => "development.eatologie.com",
"hostname" => "www",
"docroot" => '/var/www/html/'
}
puppet.manifests_path = "puppet"
puppet.manifest_file = "site.pp"
end
end
Puppet site.pp
###########################
# Eatologie Puppet Config #
###########################
# OS : Linux #
# Database : MySQL 5 #
# Web Server : Apache 2 #
# PHP version : 5.4 #
###########################
# Vim
class { 'vim': }
# Puppi
class { 'puppi': }
# Apache setup
class { "apache":
puppi => true,
puppi_helper => "myhelper",
}
apache::vhost { $fqdn :
docroot => $docroot,
server_name => $fqdn,
priority => '',
template => 'apache/virtualhost/vhost.conf.erb',
}
apache::module { 'rewrite': }
# PHP Extensions
class {"php":}
php::module { ['xdebug', 'mysql', 'curl', 'gd']:
notify => Service['apache2']
}
# MySQL Server
class { '::mysql::server':
root_password => 'abc123',
}
mysql::db { 'eatdb':
user => 'admin',
password => 'abc456',
host => 'localhost',
grant => ['all'],
charset => 'utf8',
}
# Eatologie Setup
file { $docroot:
ensure => 'directory',
}
$writeable_dirs = ["${docroot}cache/", "${docroot}cache/css/", "${docroot}cache/css/js/"]
file { $writeable_dirs:
ensure => "directory",
mode => '0777',
require => File[$docroot],
}
最佳答案
据我所知,这是您的 Vagrantfile 中的相关部分:
# Networking
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.network "private_network", ip: "192.168.33.10"
这意味着您的 Vagrantbox 可以通过 ip 192.168.33.10 和端口 8000 访问。因此,您的主机文件应该显示
192.168.33.10 development.eatologie.com
而不是
127.0.0.1 development.mysite.com
完成此更改后,您应该可以通过 development.eatologie.com:8000
访问您的网站
有关更多信息,另请参阅 forwarded ports 的 Vagrant 文档页面和 private networking 。对于专用网络部分,请考虑到,如果您为 Vagrant 盒子分配静态 IP(如您在设置中所做的那样),则必须确保该 IP 不会被本地网络上的其他设备占用。
关于具有 FQDN(完全限定域名)的 Vagrant Vhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24346921/