Code Monkey home page Code Monkey logo

chef-nginx_resources's Introduction

nginx_resources cookbook

Installs nginx and dependant modules from source in a modular fashion.

Requirements

Chef

This cookbook requires Chef 12.7 and above.

Platforms

At present, only Ubuntu < 16.04 is supported, however adding support for other distributions should be a simple matter.

Recipes

The recipes are designed to create a default nginx installation called default and will utilize the resources listed below.

Calling the standard nginx_resources::default recipe will cause the following events to occur:

  • recipes/install_user is called
    • The www-data user account is optionally created
  • recipes/install_common is called
    • The nginx_resources_instance[default] resource is created
    • A few core and override configuration files are created
    • The default site is created and optionally enabled
    • The service files are created, but not the actual service due to timing
  • recipes/install_modules is called
    • We iterate through node['nginx_resources']['source']['include_recipes'] and include recipes listed to install dependencies.
  • recipes/install_source is called
    • Package dependencies are installed
    • The nginx_resources_build[default] resources is created
  • recipes/install_service is called
    • The service is created and optionally started

Usage

  1. Within your cookbook, define an optional attribute file to customize the nginx_resources attributes to your liking. Each and every configuration parameter used by this cookbook is attribute driven.
  2. Include the nginx_resources::default recipe in your run_list.
  3. Customize the nginx_resources_site[default] resource.

Example

r = resources('nginx_resources_site[default]')
r.root '/var/www/backofficev2/current/public'
r.listen [80, '443 ssl']
r.locations [
  { 'uri' => '/',
    'try_files' => '$uri @proxy'
  },
  { 'uri' => '/admin/',
    'configs' => {
      'rewrite' => '^/admin/assets(/?.*)$ /assets$1 last'
    },
    'try_files' => '$uri @proxy'
  },
  { 'uri' => '~\.php',
    'configs' => {
      'proxy_send_timeout' => 600,
      'proxy_read_timeout' => 600
    },
    'fastcgi_pass' => '127.0.0.1:9000'
  },
  { 'uri' => '@proxy',
    'configs' => {
      'proxy_send_timeout' => 600,
      'proxy_read_timeout' => 600
    },
    'fastcgi_pass' => '127.0.0.1:9000'
  }
]
r.includes << 'include.d/fastcgi.conf'
r.includes << 'include.d/stub_status.conf'
r.includes << 'include.d/health.conf'
r.enabled true

Custom Resources

A deployment of nginx is comprised of a number of different resources. First, an nginx_resources_instance is created to define the basic folder structure. Then, any number of nginx_resources_module and nginx_resources_config are created to further customize the deployment. Lastly, a nginx_resources_build resource is created to compile and install nginx.

nginx_resources_instance

This resource builds out the folder structure for a specific deployment of nginx and it's dependant configuration files as well as creates the main configuration file.

Most of the properties have default values which lazilly load node attributes and should not generally need to be modified. Should you need modify them, however, refer to the source for more information.

With the default settings, the following structure will be created:

./var
./var/1.10.1
./var/1.10.1/logs
./var/1.10.1/logs/error.log
./var/1.10.1/html
./var/1.10.1/html/50x.html
./var/1.10.1/html/index.html
./var/1.10.1/modules
./var/1.10.1/modules/ndk_http_module.so
./etc
./etc/include.d
./etc/include.d/stub_status.conf
./etc/include.d/fastcgi.conf
./etc/include.d/health.conf
./etc/site.d
./etc/site.d/20-default
./etc/uwsgi_params
./etc/koi-utf
./etc/conf.d
./etc/conf.d/50-ssl_map.conf
./etc/conf.d/50-ssl.conf
./etc/conf.d/50-realip.conf
./etc/conf.d/50-gzip.conf
./etc/conf.d/20-mime_types.conf
./etc/conf.d/90-custom.conf
./etc/conf.d/20-core.conf
./etc/scgi_params
./etc/fastcgi.conf
./etc/nginx.conf
./etc/module.d
./etc/module.d/20-module_ndk.conf
./etc/fastcgi_params
./etc/mime.types
./etc/koi-win
./etc/win-utf
./sbin
./sbin/nginx

nginx_resources_module

This resource downloads an external dependency (ex.: the lua module), unpacks it, creates a configuration file for it, and adds the module to the node attributes for the next compile phase. It does so by wrapping nginx_resources_source and nginx_resources_config.

The following properties are required and have no defaults:

  • instance: the nginx_resources_instance name this module belongs to
  • version: the version of this module
  • checksum: the checksum of the tarball to download
  • source: the url where the tarball is downloaded from

Once downloaded, the resource will inject the module in the global module configure argument attributes found in node['nginx_resources']['source']['external_modules'].

Further properties, with defaults, may be modified and are referenced in the source file.

nginx_resources_source

This resource downloads an external dependency (ex.: the lua module) and unpacks it.

The following properties are required and have no defaults:

  • version: the version of this module
  • checksum: the checksum of the tarball to download
  • source: the url where the tarball is downloaded from

Further properties, with defaults, may be modified and are referenced in the source file.

nginx_resources_config

This resource creates a configuration file for use with nginx. Examples of this in practice may be found here.

The following properties are required and have no defaults:

  • instance: the nginx_resources_instance name this module belongs to
  • category: the namespace both for source and destination files

Further properties, with defaults, may be modified and are referenced in the source file.

nginx_resources_build

This resource builds the nginx source code for a specific nginx_resources_instance and should be smart enough not to recompile needlessly on each chef run.

The following properties are required and have no defaults:

  • root_dir: The root directory containing nginx builds
  • sbin_path: The --sbin-path or path to the nginx binary
  • conf_path: The --conf-path or path to the main nginx configuration file
  • prefix: The --prefix or directory into which to install
  • service: The service resource name to notify

Further properties, with defaults, may be modified and are referenced in the source file.

nginx_resources_maintenance

This resource is designed to create-or-remove a file which the health check looks for when determining if it should return a 503 for maintenance mode.

The following properties are all optional:

  • path: The location of the maintenance file, defaults to: node['nginx_resources']['health']['config']['maintenance_override']
  • compile_time: Boolean which determins whether to run the action of manage at compile time.
  • enable_only_if: A block which must return true/false determining whether maintenance mode should activated.
  • disable_only_if: A block which must return true/false determining whether the maintenance mode should be activated.

Further properties, with defaults, may be modified and are referenced in the source file.

chef-nginx_resources's People

Contributors

francoislapierremessier avatar jonathanserafini avatar ls-hector avatar ls-michielrensen avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.