2014-01-15 96 views
1

我有一個無業遊民的VM靴子OK,我已經通過與nginx的配置的它:如何配置nginx與廚師獨奏流浪漢?

config.vm.provision "chef_solo" do |chef| 
chef.add_recipe "nginx" 

,當它啓動時,nginx的安裝和運行。完善。 (我用berkshelf來管理食譜,其中一個來自opscode)
現在我想實際配置nginx,在這種情況下作爲反向代理運行。我似乎無法找到如何。我可以準備好一個conf文件並將它發送給虛擬機,但我相信還有另一種方法可以利用該cookbook。最好的選擇是能夠按照上面描述的直接從Vagrant文​​件中配置它。也許使用像這裏描述的定製json數據之類的東西http://docs.vagrantup.com/v2/provisioning/chef_solo.html
它看起來是這樣的:

chef.json = { 
    "nginx" => { 

但在http://community.opscode.com/cookbooks/nginx菜譜頁面是有點神祕給我,還有有趣的選擇,但我不知道如何包含/使用它們。

+0

你見過在GitHub上的文檔:https://github.com/opscode-cookbooks/nginx – sethvargo

+0

在廚師界的格式網站對於閱讀食譜的自述文件不是特別好。嘗試在[GitHub頁面](https://github.com/opscode-cookbooks/nginx) – cassianoleal

+0

感謝您的意見。事實上,它更容易閱讀,但我還沒有理解進入Vagrantfile的格式。任何文檔或例子將不勝感激。 – Bastian

回答

0

如果您想將nginx配置爲反向代理,那麼您需要編寫一個食譜配方,調用cookbook_file資源或template資源。我建議使用後者,因爲稍後它會更加靈活,並且會爲您提供可供其他配方使用的可重複使用的模板。

我建議你在這裏閱讀文檔: http://docs.opscode.com/resource_template.html#using-templates

,如果你想看到從一個真正的食譜反向代理的例子。看看這裏:

https://github.com/lusis/chef-kibana/blob/master/recipes/nginx.rb

https://github.com/lusis/chef-kibana/blob/master/templates/default/kibana-nginx.conf.erb

希望這有助於。

0

這是爲我工作:

Vagrant.configure("2") do |config| 

    config.vm.box = "opscode-ubuntu-14.04" 
    config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box" 

    config.omnibus.chef_version = :latest 

    config.vm.provision "shell", inline: "echo 'set nocp' > /home/vagrant/.vimrc" 

    config.vm.define "nginx" do |nginx| 

     nginx.vm.network "private_network", ip: "192.168.33.14" 

     nginx.vm.provision :chef_solo do |chef| 
      chef.cookbooks_path = "cookbooks" 
      chef.add_recipe "nginx" 

      chef.json = { 
       :nginx => { 
        dir: '/etc/nginx' # this is the default value, sample only 
       } 
      } 
     end 

     nginx.vm.provision "shell", 
      inline: "echo -e $1 > /etc/nginx/conf.d/nginx.conf", 
      args: [<<-EOS 
       server { 
        listen *:80; 

        location ~ ^/ { 
         proxy_pass http://192.168.33.11:8080; 
        } 
       } 
      EOS 
      ] 

    end 

需要注意的是,我寫nginx.config,我可以寫其他每個站點CONFIGS(domain1.conf,domain2.conf),他們都將被加載。

我最終需要拉下了不少食譜:

https://github.com/opscode-cookbooks/nginx 
    https://github.com/opscode-cookbooks/build-essential 
    https://github.com/opscode-cookbooks/ohai 
    https://github.com/opscode-cookbooks/bluepill  
     https://github.com/opscode-cookbooks/rsyslog 
    https://github.com/hw-cookbooks/runit 
    ?? 
     https://github.com/opscode-cookbooks/yum 
+0

請注意,我仍需要重新加載vagrant來獲取nginx.conf配置以重新加載。 –