如何用无业游民和厨师创建虚拟主机 [英] How to create a virtual host with vagrant and chef
问题描述
我已经安装了第一台无业游民的机器,并通过刀子下载了一些食谱.
I've setup my first vagrant machine, with some cookbooks downloaded through knife.
我对虚拟主机的设置感到困惑.
I am stuck with the setup of a virtual host.
这是我的Vagrantfile:
Here's my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.provision :chef_solo do |chef|
chef.json = {
"mysql" => {
"server_root_password" => "admin",
"server_repl_password" => "admin",
"server_debian_password" => "admin"
},
"apache" => {
"listen_address" => "0.0.0.0"
}
}
chef.add_recipe "apt"
chef.add_recipe "vim"
chef.add_recipe "openssl"
chef.add_recipe "apache2"
chef.add_recipe "mysql"
chef.add_recipe "mysql::server"
chef.add_recipe "php"
# chef.add_recipe "php::module_apc"
chef.add_recipe "php::module_curl"
chef.add_recipe "php::module_mysql"
chef.add_recipe "apache2::mod_php5"
chef.add_recipe "apache2::mod_rewrite"
end
web_app "blog_site" do
server_name "blog"
server_aliases [ "blog.#{node['domain']}", node['fqdn'] ]
docroot "/var/www/blog_site"
end
#
end
我已经看到此处,如果我想通过apache食谱设置虚拟主机我必须使用"web_app"定义.
I've seen here that if I want to set a virtual host through the apache cookbook I have to use the "web_app" definition.
我已将web_app
添加到无业游民的文件中,但出现此错误
I've added the web_app
to the vagrant file but I am getting this error
in `block in <top (required)>': undefined method `web_app' for main:Object (NoMethodError)
这意味着(我认为)语法错误:)
that means (I think) that syntax is wrong :)
我该如何解决?定义"web_app"在哪里?
How can I fix this? Where the definition "web_app" goes?
推荐答案
对web_app
的调用必须包含在配方中.
Invocation of web_app
must go into a recipe.
例如,您可以在也名为my-site
的目录中创建my-site
食谱.至少必须有3个文件:
For example, you can create my-site
cookbook in a directory which is also named my-site
. There must be at least 3 files:
-
my-site/metadata.rb
,带有基本元数据:
name "my-site"
description "Adds Apache domain configuration for my site"
my-site/recipes/default.rb
:
include_recipe "apache2"
web_app "my_site" do
server_name "my-site.localhost"
server_aliases ["www.my-site.localhost"]
docroot "/vagrant"
end
my-site/templates/default/web_app.conf.erb
-从apache2
食谱(apache2/templates/default/web_app.conf.erb
)的示例模板中复制其内容.
my-site/templates/default/web_app.conf.erb
- copy it's contents from example template from apache2
cookbook (apache2/templates/default/web_app.conf.erb
).
请注意,我将"my-site.localhost"
用作ServerName.您应将其替换为您的域名,因为代码中未定义node['fqdn']
和node['domain']
. DocRoot也必须是您网站的正确路径-可能是您无所事事的同步目录,默认情况下为"/vagrant"
(您可以更改).
Note that I use "my-site.localhost"
as ServerName. You should replace it with your domain name, because node['fqdn']
and node['domain']
are not defined in your code. DocRoot must be also correct path to your site - it probably will be your vagrant synced directory, which is "/vagrant"
by default (you can change it).
您可能还想将192.168.33.10 my-site.localhost
添加到主机(您的实际操作系统)上的hosts
文件中.
You'll porbably also want to add 192.168.33.10 my-site.localhost
to your hosts
file on the host machine (your actual OS).
我已经撰写了有关Vagrant和Chef独奏的介绍性帖子,对您可能有用:
I've written an introductory post on Vagrant and Chef solo, it may be useful to you: http://scriptin.github.io/2013-05-09/vagrant-chef-intro.html
这篇关于如何用无业游民和厨师创建虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!