如何用无业游民和厨师创建虚拟主机

编程入门 行业动态 更新时间:2024-10-15 14:17:41
本文介绍了如何用无业游民和厨师创建虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经安装了第一台无业游民的机器,并通过刀子下载了一些食谱.

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 = "files.vagrantup/precise32.box" config.vmwork :forwarded_port, guest: 80, host: 8080 config.vmwork :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独奏的介绍性帖子,对您可能有用: scriptin.github.io/2013-05-09/vagrant-chef-intro.html

    I've written an introductory post on Vagrant and Chef solo, it may be useful to you: scriptin.github.io/2013-05-09/vagrant-chef-intro.html

  • 更多推荐

    如何用无业游民和厨师创建虚拟主机

    本文发布于:2023-10-07 13:13:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1469477.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:无业游民   厨师   如何用   虚拟主机

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!