How to install Nginx by Chef
This is an example how to install Nginx by Chef. Previously I have written article how to install Chef on Ubuntu and now we will try to install the first cookbook on this environment.
1. Download cookbook
Create cookbook directory:
sudo mkdir -p /var/chef/cookbooks
sudo chown ubuntu:ubuntu /var/chef/cookbooks
cd /var/chef/cookbooks
git init
echo "This is a cookbooks directory" > readme.txt
git add *
git commit -m "init master"Download “nginx” cookbook and place it in /var/chef/cookbooks directory with dependencies:
knife cookbook site install nginxFix types_hash_max_size:
nano /var/chef/cookbooks/nginx/templates/default/nginx.conf.erbPut in bottom of the http section the text:
types_hash_max_size 8192;Upload cookbooks to the Chef Server
knife cookbook upload ohai
knife cookbook upload build-essential
knife cookbook upload yum
knife cookbook upload bluepill
knife cookbook upload runit
knife cookbook upload nginxList active nodes
knife node listSelect front node and apply recipe for it
knife node run_list add front_node 'nginx::default'Show the node to ensure that the run_list contains the recipe
knife node show front_nodeChef WebUI customization
/usr/share/chef-server-webui/config/rack.rb
use Rack::ContentLength
if prefix = ::Merb::Config[:path_prefix]
use Merb::Rack::PathPrefix, prefix
end
use Merb::Rack::Static, Merb.dir_for(:public)
run Merb::Rack::Application.newadd to /usr/share/chef-server-webui/config/environments/production.rb:
c[:path_prefix] = ‘/webui’
