Chef cookbook for provisioning Ruby (RVM), Passenger (Open Source and Enterprise editions) and Nginx.
- Ubuntu
For the impatient:
gem install knife-solo
Note: Please read http://matschaffer.github.io/knife-solo/ for more info about Knife Solo.
knife solo init <my-project-name>
chdir into your new folder
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.
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"
}
]
}
}
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
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.
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.
Key | Type | Description | Default |
---|---|---|---|
['passenger-nginx']['ruby_version'] | String | Numerical string of Ruby version | 2.1.0 |
['passenger-nginx']['passenger']['version'] | String | Passenger Gem Version | 4.0.53 |
['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 |
['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]['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.
|
['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 |
['passenger-nginx']['nginx']['user'] | String | User to run Nginx as | www-data |
['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']['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 |
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"
}
]
}
}
-
You must install the license key yourself as
/etc/passenger-enterprise-license
. This cookbook will not install the license key for you. -
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"
}
]
}
}
-
You must install the certificate and key yourself. This cookbook will not install them for you.
-
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
}
]
}
}
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.
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.