Giter Club home page Giter Club logo

chef-passenger-nginx's Introduction

Chef passenger-nginx Cookbook

Chef cookbook for provisioning Ruby (RVM), Passenger (Open Source and Enterprise editions) and Nginx.

Supported Platforms

  • Ubuntu

Quick Start Guide

For the impatient:

1. Install Knife Solo

gem install knife-solo

Note: Please read http://matschaffer.github.io/knife-solo/ for more info about Knife Solo.

2. Prepare a new chef/knife solo project

knife solo init <my-project-name>

chdir into your new folder

3. Add the passenger-nginx cookbook

Add the following line to the file Berksfile:

cookbook "passenger-nginx", git: "https://github.com/ballistiq/chef-passenger-nginx.git"

Run berks install

Note: Please refer to http://berkshelf.com/ to read more about using Berkshelf to manage cookbooks.

4. Add and configure the node

In our example, we'll use vagrant running on localhost. The name of the json file should correspond to your hostname. E.g. if you are deploying to server1.ballistiq.com, it should be server1.ballistiq.com.json.

So we would create a file /nodes/localhost.json:

{
  "run_list": [
    "recipe[passenger-nginx]"
  ],

  "passenger-nginx": {
    "ruby_version": "2.1.0",
    "passenger": {
      "version": "4.0.53"
    },
    "apps": [
      {
        "name": "my-application",
        "server_name": "example.com www.example.com",
        "listen": 80,
        "root": "/var/www/my-application",
        "ruby_gemset": "my-application",
        "app_env": "staging"
      }
    ]
  }
}

5. Prepare the server

We use knife solo to prepare and cook the server. Alter the following command to use your username, server host and port.

Preparation copies Chef to the server.

knife solo prepare vagrant@localhost -p 2222

6. Cook the server

Cooking actually runs your recipes on the server.

knife solo cook vagrant@localhost -p 2222

Once this is done, it should have installed RVM, Ruby, Passenger, Nginx and configured an application for you.

Now you can run your Capistrano scripts to deploy to the server and off you go.

Need to make changes to the cookbook?

If you are configuring an application that has some funky requirements and need to change some stuff in this cookbook, clone the repository and copy it to site-cookbooks. Remove it from the Berksfile as you are now using the version in your project. Make any edits and enjoy.

Important Attributes

Key Type Description Default
['passenger-nginx']['ruby_version'] String Numerical string of Ruby version 2.3.3
['passenger-nginx']['passenger']['version'] String Passenger Gem Version 4.1.1
['passenger-nginx']['passenger']['enterprise_download_token'] String If using Passenger Enterprise, log in to the customer area and get the download token. This will give the recipe access to download the Enterprise Gem from Phusion directly. nil

Attributes for Configuring Applications in Nginx

['passenger-nginx']['passenger']['apps'] Array Array of applications to configure []
['passenger-nginx']['passenger']['apps'][n]['config_source'] String Override the source of the config file. Used for completely custom configs. E.g. app1.conf.erb nginx_app.conf.erb
['passenger-nginx']['passenger']['apps'][n]['config_cookbook'] String Override the cookbook of your custom config.
['passenger-nginx']['passenger']['apps'][n]['name'] String name-of-your-application-like-this
['passenger-nginx']['passenger']['apps'][n]['server_name'] String Name-based virtual hosting: "example.com www.example.com" nil
['passenger-nginx']['passenger']['apps'][n]['listen'] Integer What port to listen to: e.g. 80
['passenger-nginx']['passenger']['apps'][n]['http2'] Boolean Use HTTP2 false
['passenger-nginx']['passenger']['apps'][n]['listen_redirect'] Integer What port to listen to for http to https redirects: e.g. 8080
['passenger-nginx']['passenger']['apps'][n]['root'] String Path to application: e.g. "/var/www/my-application"
['passenger-nginx']['passenger']['apps'][n]['ruby_gemset'] String Use a specific gemset for the application.
['passenger-nginx']['passenger']['apps'][n]['app_env'] String Environment to run your app. E.g. 'staging' production
['passenger-nginx']['passenger']['apps'][n]['passenger_min_instances'] Integer [https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerMinInstances](https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerMinInstances) 1
['passenger-nginx']['passenger']['apps'][n]['passenger_max_instances'] Integer [https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerMaxInstances](https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerMaxInstances) 0
['passenger-nginx']['passenger']['apps'][n]['passenger_concurrency_model'] String [https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerConcurrencyModel](https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerConcurrencyModel) process
['passenger-nginx']['passenger']['apps'][n]['passenger_thread_count'] Integer [https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerThreadCount](https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerThreadCount) 1
['passenger-nginx']['passenger']['apps'][n]['ssl_certificate'] String Path to SSL certificate: e.g. "/opt/nginx/keys/app.bundle.crt"
['passenger-nginx']['passenger']['apps'][n]['ssl_certificate_key'] String Path to SSL certificate key: e.g. "/opt/nginx/keys/app.key"
['passenger-nginx']['passenger']['apps'][n]['redirect_http_https'] Boolean If you want to redirect requests on port 80 to https:// (443) then set this to true. false
['passenger-nginx']['passenger']['apps'][n]['client_body_buffer_size'] String See: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size
['passenger-nginx']['passenger']['apps'][n]['client_max_body_size'] String See: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
['passenger-nginx']['passenger']['apps'][n]['custom_config'] String or Array Any additional Nginx configuration that you want for the app. E.g.
"custom_config": [
  "expires max;",
  "location ~* \\.(eot|ttf|woff)$ {",
  "  add_header Access-Control-Allow-Origin *;",
  "}"
</tt></td>
['passenger-nginx']['passenger']['apps'][n]['gzip_static'] Boolean Turn on gzip_static - delivers gz file if it exists false
['passenger-nginx']['passenger']['apps'][n]['access_log'] String Location for access log nil - defaults to global access log
['passenger-nginx']['passenger']['apps'][n]['error_log'] String Location for error log nil - defaults to global error log

Attributes for Tuning

['passenger-nginx']['nginx']['user'] String User to run Nginx as www-data
['passenger-nginx']['nginx']['http2'] Boolean Add HTTP2 module false
['passenger-nginx']['nginx']['extra_configure_flags'] String Compile additional modules. E.g. "--with-http_gzip_static_module"
['passenger-nginx']['nginx']['worker_processes'] Integer Number of Nginx worker processes to run 2
['passenger-nginx']['nginx']['worker_connections'] Integer Number of connections each worker can handle 1024
['passenger-nginx']['nginx']['worker_rlimit_nofile'] Integer Number of files Nginx can open. Should be quite high for a high performance system. 4096
['passenger-nginx']['nginx']['access_log'] String Location for access log. "off" to not use this. logs/access.log
['passenger-nginx']['nginx']['error_log'] String Location for error log. "off" to not use this. logs/error.log
['passenger-nginx']['passenger']['rolling_restarts'] String If using Passenger Enterprise, this enables rolling restarts. Can be 'on' or 'off'. off
['passenger-nginx']['passenger']['max_pool_size'] Integer Max Passenger pool size 15
['passenger-nginx']['passenger']['min_instances'] Integer Minimum number of instances of Passenger to run 2
['passenger-nginx']['passenger']['pool_idle_time'] Integer Pool idle time 300
['passenger-nginx']['passenger']['max_instances_per_app'] Integer Max instances per app 0

Usage

Basic Usage

Include passenger-nginx in your node's run_list:

{
  "run_list": [
    "recipe[passenger-nginx]"
  ],

  "passenger-nginx": {
    "ruby_version": "2.1.0",
    "passenger": {
      "version": "4.0.53"
    },
    "apps": [
      {
        "name": "my-application",
        "server_name": "example.com www.example.com",
        "listen": 80,
        "root": "/var/www/my-application",
        "ruby_gemset": "my-application",
        "app_env": "staging"
      }
    ]
  }
}

Passenger Enterprise

  1. You must install the license key yourself as /etc/passenger-enterprise-license. This cookbook will not install the license key for you.

  2. Get the download token from Phusion's customer area and add it as an attribute as seen below.

{
  "run_list": [
    "recipe[passenger-nginx]"
  ],

  "passenger-nginx": {
    "ruby_version": "2.1.0",
    "passenger": {
      "version": "4.0.53",
      "enterprise_download_token": "xxxxxxxxxxxxxxxxxx"
    },
    "apps": [
      {
        "name": "my-application",
        "server_name": "example.com www.example.com",
        "listen": 80,
        "root": "/var/www/my-application",
        "ruby_gemset": "my-application"
      }
    ]
  }
}

SSL Certificates and Keys

  1. You must install the certificate and key yourself. This cookbook will not install them for you.

  2. Add the absolute paths as attributes as seen below.

{
  "run_list": [
    "recipe[passenger-nginx]"
  ],

  "passenger-nginx": {
    "ruby_version": "2.1.0",
    "passenger": {
      "version": "4.0.53",
      "enterprise_download_token": "xxxxxxxxxxxxxxxxxx"
    },
    "apps": [
      {
        "name": "my-secure-application",
        "server_name": "example.com www.example.com",
        "listen": 443,
        "root": "/var/www/my-application",
        "ruby_gemset": "my-application",
        "ssl_certificate": "/opt/nginx/keys/app.bundle.crt",
        "ssl_certificate_key": "/opt/nginx/keys/app.key",
        "redirect_http_https": true
      }
    ]
  }
}

Changelog

2 January 2017 - 0.9.18 - Added support for HTTP2, which was added in Nginx 1.9.5+.

29 June 2016 - 0.9.17 - Updated init.d script with hashbang so that it will work on newer Ubuntu release.

25 August 2015 - 0.9.16 - Merged changes by @jh125486 adding ability to listen to different ports, and changed redirect from rewrite regex to return 301.

21 April 2015 - 0.9.15 - Enabled totally custom config files.

16 February 2015 - 0.9.14 - Made server_name var optional.

15 January 2015 - 0.9.13 - Added internal monitoring.

4 December 2014 - 0.9.12 - Added PCRE packages to installation to ensure that Nginx installation has a clean run.

25 November 2014 - 0.9.11 - Custom configs can now be passed in an array, for longer custom configurations.

17 November 2014 - 0.9.10 - Added options for client_max_body_size and client_body_buffer_size

17 November 2014 - 0.9.9 - Made Gzip static default

17 November 2014 - 0.9.8 - Fixed bug with no extra configure flags causing script to barf.

14 November 2014 - 0.9.7 - Added Nginx extra configure flags to attributes.

11 November 2014 - 0.9.6 - Added libcurl4-openssl-dev to apt packages. Required by Passenger...

11 November 2014 - 0.9.5 - Fixed issue with apt eager installing packages. RVM will automatically install required packages.

8 November 2014 - 0.9.4 - Fixed bug with rolling restarts directive barfing on open source edition of Passenger (even if it says 'off').

5 November 2014 - 0.9.3 - Added rolling restarts to Passenger. Recipe now creates gemsets if they are defined.

4 November 2014 - 0.9.2 - Fixed issue with Passenger not starting because Ruby is not running via a wrapper. Added app variables app_env to set environment, ruby_gemset to set a specific gemset for the application and custom_config to allow any additional custom configuration that you want passed into Nginx.

3 November 2014 - 0.9.1 - Install GPG keys before attempting to install RVM. New RVM appears to have changed keys which was causing failure on run. Default Ruby is now 2.1.4.

License and Authors

Author:: Leonard Teo ([email protected])

This is licensed under the MIT license. Enjoy!

Copyright (C) 2014 Ballistiq Digital, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

chef-passenger-nginx's People

Contributors

concatime avatar jh125486 avatar leonardteo avatar thegrandpoobah avatar tjgfernandes avatar

Watchers

 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.