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.

  1. Create Berksfile in your Chef repository including my_cookbook:
    mma@laptop:~/chef-repo $ subl Berksfile
    
    cookbook 'my_cookbook', path: './cookbooks/my_cookbook'
  2. Create or edit a role called web_server with 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" ...

Get Chef: Powerful Infrastructure Automation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.