Creating nginx virtual hosts
Assuming you have nginx installed, you want to manage your websites with Chef. You need to create an nginx configuration file for your website and upload your HTML file(s). Let's see how to do this.
Getting ready
Make sure that you have a cookbook named my_cookbook, as described in the Creating and using cookbooks recipe in Chapter 1, Chef Infrastructure.
Create a
Berksfilein your Chef repository includingmy_cookbook:mma@laptop:~/chef-repo $ subl Berksfile cookbook 'my_cookbook', path: './cookbooks/my_cookbook'
Create or edit a role called
web_serverwith the following content:mma@laptop:~/chef-repo $ subl roles/web_server.rb name "web_server" run_list "recipe[my_cookbook]" default_attributes "nginx" => { "init_style" => "init", "default_site_enabled" => false }
Upload the role to the Chef server:
mma@laptop:~/chef-repo $ knife role from file web_server.rb Updated Role web_server!
Add the
web_serverrole to your node's run list:mma@laptop:~/chef...