Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

RSS

nginx_conf (8) Versions 1.0.0

Installs/Configures nginx_conf

Berkshelf/Librarian
Policyfile
Knife
cookbook 'nginx_conf', '= 1.0.0'
cookbook 'nginx_conf', '= 1.0.0', :supermarket
knife cookbook site install nginx_conf
knife cookbook site download nginx_conf
README
Dependencies
Changelog
Quality

Circle CI

Description

Manage nginx server configuration files.

Requirements

  • Chef >= 11.0
  • Nginx cookbook

Attributes

See a list of all attributes.

Usage

Add the nginx_conf recipe to your runlist.

confs

Rather then accessing the LWRP directly, add a site hash to the confs attribute list.

node['nginx_conf']['confs'] = [{
  'test1.mywebsite.com' => {
    'socket' => "/var/www/myapp/shared/tmp/sockets/unicorn.socket"
  },
  'test2.mywebsite.com' => {
    'root' => "/var/www/myapp",
    'site_type' => :static
  },
  'test3.mywebsite.com' => {
    'action' => :disable
  },
  'test4.mywebsite.com' => {
    'action' => :delete
  },
}]

Create

Creates a nginx configuration in the sites-available directory, tests it, symlinks to sites-enabled, and restarts nginx. See a list of all LWRP attributes.

nginx_conf_file "mywebsite.com" do
  socket "/var/www/myapp/shared/tmp/sockets/unicorn.socket"
end

Outputs to sites-available/mywebsite.com:

server {
  listen 80;

  server_name mywebsite.com;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unix:/var/www/myapp/shared/tmp/sockets/unicorn.socket;
  }
}

Creating a static conf is even easier.

nginx_conf_file "mywebsite.com" do
  root "/var/www/myapp"
  site_type :static
end

Outputs to sites-available/mywebsite.com:

server {
  listen 80;

  server_name mywebsite.com;

  root "/var/www/myapp";
}

SSL

To configure ssl:

nginx_conf_file "mywebsite.com" do
  ssl({'public' => 'public_key', 'private' => 'private_key', 'name' => 'mywebsite'})
end

NOTE The name attribute is optional. It defaults to the resource conf_name or resource name. It is only necessary, if you want to define the public and private key file name. EXE Using the value above, the file names would be mywebsite.public.crt & mywebsite.private.key respectively.

Disable

Removes the symlink between sites-enabled and sites-available for the named configuration.

nginx_conf_file "mywebsite.com" do
  action :disable
end

Delete

Removes the symlink and deletes the configuration:

nginx_conf_file "mywebsite.com" do
  action :delete
end

SSL Delete

Deleting SSL certs is managed by the delete resource, but there are some situations where you want to manage the deletion yourself. To do this, set the [:nginx_conf][:defaults][:delete][:ssl] to false or add :delete false to the nginx_conf_file ssl attribute hash.

nginx_conf_file "mywebsite.com" do
  action :delete
  ssl({'delete' => false})
end

Testing

We use foodcritic and chefspec to check basic functionality. To run tests:

bundle install
berks install
strainer test

v0.0.6:

  • Use nginx user and group attribute for template owner.
  • [#4] Add ssl support.
  • Allow options to use Hash or Array.

v0.0.7:

  • Use nginx binary attribute for nginx location.

v0.0.8:

  • removed available_sites_repo since we are integrating more with nginx cookbook
  • removed enabled_sites_repo since we are integrating more with nginx cookbook
  • added nginx_conf_options function to handle template configuration

v0.0.9:

  • Added site_type to LWRP to manually set dynamic vs static sites and updated docs.

v0.1.0:

  • Added single upstream to LWRP.

v0.1.1:

  • Allow for an array of server_name attributes.
  • conf_name attribute added. Define the conf_name independently of the server_name.

v0.2:

  • Fixed ssl creation issues.
  • Update listen resource to allow for arrays.

v0.2.1:

  • removed explicit 443 listen port.

v0.2.2:

  • updated default recipe to actually mimic LWRP reources.

v0.2.3:

  • added ssl tests
  • added ssl docs
  • added ssl name attribute
  • merged mwhooker to fix test resource name.
  • added ssl cert/key delete.

v0.2.4:

  • added limit_except (Thanks namtzigla)
  • fixed ssl delete cert issue with a new attribute
  • switched nginx_group declaration

Foodcritic Metric
            

1.0.0 passed this metric