PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://bitbucket.org/mxvzr/chef-cookbook-nginx
Markdown | 378 lines | 298 code | 80 blank | 0 comment | 0 complexity | 9c23dc5d10b213081d0d00af9bdd1b71 MD5 | raw file
Possible License(s): Apache-2.0
  1. Description
  2. ===========
  3. Installs nginx from package OR source code and sets up configuration
  4. handling similar to Debian's Apache2 scripts.
  5. Requirements
  6. ============
  7. Cookbooks
  8. ---------
  9. The following cookbooks are direct dependencies because they're used
  10. for common "default" functionality.
  11. * build-essential (for nginx::source)
  12. * ohai (for nginx::ohai_plugin)
  13. The following cookbook is not a strict dependency because its use can
  14. be controlled by an attribute, so it may not be a common "default."
  15. * runit (for nginx::source)
  16. On RHEL family distros, the "yum" cookbook is required for "`recipe[yum::epel]`".
  17. Platform
  18. --------
  19. The following platforms are supported and tested under test kitchen:
  20. * Ubuntu 10.04, Ubuntu 12.04
  21. * CentOS 5.8, 6.3
  22. Other Debian and RHEL family distributions are assumed to work.
  23. Attributes
  24. ==========
  25. Node attributes for this cookbook are logically separated into
  26. different files. Some attributes are set only via a specific recipe.
  27. ## default.rb
  28. Generally used attributes. Some have platform specific values. See
  29. `attributes/default.rb`. "The Config" refers to "nginx.conf" the main
  30. config file.
  31. **v0.101.0 - Attribute Change**: `node['nginx']['url']` is now
  32. `node['nginx']['source']['url']` as the URL was only used when
  33. retrieving the source to build Nginx.
  34. * `node['nginx']['dir']` - Location for Nginx configuration.
  35. * `node['nginx']['log_dir']` - Location for Nginx logs.
  36. * `node['nginx']['user']` - User that Nginx will run as.
  37. * `node['nginx']['group]` - Group for Nginx.
  38. * `node['nginx']['binary']` - Path to the Nginx binary.
  39. * `node['nginx']['init_style']` - How to run Nginx as a service when
  40. using `nginx::source`. Values can be "runit", "init" or "bluepill".
  41. When using runit or bluepill, those recipes will be included as well
  42. and are dependencies of this cookbook. Not used in the `nginx`
  43. recipe because the package manager's init script style for the
  44. platform is assumed.
  45. * `node['nginx']['pid']` - Location of the PID file.
  46. * `node['nginx']['keepalive']` - Whether to use `keepalive_timeout`,
  47. any value besides "on" will leave that option out of the config.
  48. * `node['nginx']['keepalive_timeout']` - used for config value of
  49. `keepalive_timeout`.
  50. * `node['nginx']['worker_processes']` - used for config value of
  51. `worker_processes`.
  52. * `node['nginx']['worker_connections']` - used for config value of
  53. `events { worker_connections }`
  54. * `node['nginx']['worker_rlimit_nofile']` - used for config value of
  55. `worker_rlimit_nofile`. Can replace any "ulimit -n" command. The
  56. value depend on your usage (cache or not) but must always be
  57. superior than worker_connections.
  58. * `node['nginx']['multi_accept']` - used for config value of `events {
  59. multi_accept }`. Try to accept() as many connections as possible.
  60. Disable by default.
  61. * `node['nginx']['event']` - used for config value of `events { use
  62. }`. Set the event-model. By default nginx looks for the most
  63. suitable method for your OS.
  64. * `node['nginx']['server_names_hash_bucket_size']` - used for config
  65. value of `server_names_hash_bucket_size`.
  66. * `node['nginx']['disable_access_log']` - set to true to disable the
  67. general access log, may be useful on high traffic sites.
  68. * `node['nginx']['default_site_enabled']` - enable the default site
  69. * `node['nginx']['install_method']` - Whether nginx is installed from
  70. packages or from source.
  71. * `node['nginx']['types_hash_max_size']` - Used for the
  72. `types_hash_max_size` configuration directive.
  73. * `node['nginx']['types_hash_bucket_size']` - Used for the
  74. `types_hash_bucket_size` configuration directive.
  75. * `node['nginx']['proxy_read_timeout']` - defines a timeout (between two
  76. successive read operations) for reading a response from the proxied server.
  77. * `node['nginx']['client_max_body_size']` - specifies the maximum accepted body
  78. size of a client request, as indicated by the request header Content-Length.
  79. ### Attributes for configuring the gzip module
  80. * `node['nginx']['gzip']` - Whether to use gzip, can be "on" or "off"
  81. * `node['nginx']['gzip_http_version']` - used for config value of `gzip_http_version`.
  82. * `node['nginx']['gzip_comp_level']` - used for config value of `gzip_comp_level`.
  83. * `node['nginx']['gzip_proxied']` - used for config value of `gzip_proxied`.
  84. * `node['nginx']['gzip_types']` - used for config value of `gzip_types` - must be an Array.
  85. ### Attributes set in recipes
  86. *nginx::source*
  87. * `node['nginx']['daemon_disable']` - Whether the daemon should be
  88. disabled which can be true or false; disable the daemon (run in the
  89. foreground) when using a service supervisor such as runit or
  90. bluepill for "init_style". This is automatically set in the
  91. `nginx::source` recipe when the init style is not bluepill or runit.
  92. *nginx::authorized_ips*
  93. * `node['nginx']['remote_ip_var']` - The remote ip variable name to
  94. use.
  95. * `node['nginx']['authorized_ips']` - IPs authorized by the module
  96. *nginx::http_realip_module*
  97. From: http://wiki.nginx.org/HttpRealIpModule
  98. * `node['nginx']['realip']['header']` - Header to use for the RealIp
  99. Module; only accepts "X-Forwarded-For" or "X-Real-IP"
  100. * `node['nginx']['realip']['addresses']` - Addresses to use for the
  101. `http_realip` configuration.
  102. ## source.rb
  103. These attributes are used in the `nginx::source` recipe. Some of them
  104. are dynamically modified during the run. See `attributes/source.rb`
  105. for default values.
  106. * `node['nginx']['source']['url']` - (versioned) URL for the Nginx
  107. source code. By default this will use the version specified as
  108. `node['nginx']['version'].
  109. * `node['nginx']['source']['prefix']` - (versioned) prefix for
  110. installing nginx from source
  111. * `node['nginx']['source']['conf_path']` - location of the main config
  112. file, in `node['nginx']['dir']` by default.
  113. * `node['nginx']['source']['modules']` - Array of modules that should
  114. be compiled into Nginx by including their recipes in
  115. `nginx::source`.
  116. * `node['nginx']['source']['default_configure_flags']` - The default
  117. flags passed to the configure script when building Nginx.
  118. * `node['nginx']['configure_flags']` - Preserved for compatibility and
  119. dynamically generated from the
  120. `node['nginx']['source']['default_configure_flags']` in the
  121. `nginx::source` recipe.
  122. ## geoip.rb
  123. These attributes are used in the `nginx::http_geoip_module` recipe.
  124. Please note that the `country_dat_checksum` and `city_dat_checksum`
  125. are based on downloads from a datacenter in Fremont, CA, USA. You
  126. really should override these with checksums for the geo tarballs from
  127. your node location.
  128. **Note** The upstream, maxmind.com, may block access for repeated
  129. downloads of the data files. It is recommended that you download and
  130. host the data files, and change the URLs in the attributes.
  131. * `node['nginx']['geoip']['path']` - Location where to install the
  132. geoip libraries.
  133. * `node['nginx']['geoip']['enable_city']` - Whether to enable City
  134. data
  135. * `node['nginx']['geoip']['country_dat_url']` - Country data tarball
  136. URL
  137. * `node['nginx']['geoip']['country_dat_checksum']` - Country data
  138. tarball checksum
  139. * `node['nginx']['geoip']['city_dat_url']` - City data tarball URL
  140. * `node['nginx']['geoip']['city_dat_checksum']` - City data tarball
  141. checksum
  142. * `node['nginx']['geoip']['lib_version']` - Version of the GeoIP
  143. library to install
  144. * `node['nginx']['geoip']['lib_url']` - (Versioned) Tarball URL of the
  145. GeoIP library
  146. * `node['nginx']['geoip']['lib_checksum']` - Checksum of the GeoIP
  147. library tarball
  148. ## upload_progress.rb
  149. These attributes are used in the `nginx::upload_progress_module`
  150. recipe.
  151. * `node['nginx']['upload_progress']['url']` - URL for the tarball.
  152. * `node['nginx']['upload_progress']['checksum']` - Checksum of the
  153. tarball.
  154. ## passenger.rb
  155. These attributes are used in the `nginx::passenger` recipe.
  156. * `node['nginx']['passenger']['version']` - passenger gem version
  157. * `node['nginx']['passenger']['root']` - passenger gem root path
  158. * `node['nginx']['passenger']['max_pool_size']` - maximum passenger
  159. pool size (default=10)
  160. * `node['nginx']['passenger']['ruby']` - Ruby path for Passenger to
  161. use (default=`$(which ruby)`)
  162. * `node['nginx']['passenger']['spawn_method']` - passenger spawn
  163. method to use (default=`smart-lv2`)
  164. * `node['nginx']['passenger']['use_global_queue']` - turns on or off
  165. global queuing (default=`on`)
  166. * `node['nginx']['passenger']['buffer_response']` - turns on or off
  167. response buffering (default=`on`)
  168. * `node['nginx']['passenger']['max_pool_size']` - passenger maximum
  169. pool size (default=`6`)
  170. * `node['nginx']['passenger']['min_instances']` - minimum instances
  171. (default=`1`)
  172. * `node['nginx']['passenger']['max_instances_per_app']` - maximum
  173. instances per app (default=`0`)
  174. * `node['nginx']['passenger']['pool_idle_time']` - passenger pool idle
  175. time (default=`300`)
  176. * `node['nginx']['passenger']['max_requests']` - maximum requests
  177. (default=`0`)
  178. ## echo.rb
  179. These attributes are used in the `nginx::http_echo_module` recipe.
  180. * `node['nginx']['echo']['version']` - The version of `http_echo` you
  181. want (default: 0.40)
  182. * `node['nginx']['echo']['url']` - URL for the tarball.
  183. * `node['nginx']['echo']['checksum']` - Checksum of the tarball.
  184. Recipes
  185. =======
  186. This cookbook provides two main recipes for installing Nginx.
  187. * default.rb: *Use this recipe* if you have a native package for
  188. Nginx.
  189. * source.rb: *Use this recipe* if you do not have a native package for
  190. Nginx, or if you want to install a newer version than is available,
  191. or if you have custom module compilation needs.
  192. Several recipes are related to the `source` recipe specifically. See
  193. that recipe's section below for a description.
  194. ## default.rb
  195. The default recipe will install Nginx as a native package for the
  196. system through the package manager and sets up the configuration
  197. according to the Debian site enable/disable style with `sites-enabled`
  198. using the `nxensite` and `nxdissite` scripts. The nginx service will
  199. be managed with the normal init scripts that are presumably included
  200. in the native package.
  201. Includes the `ohai_plugin` recipe so the plugin is available.
  202. ## ohai_plugin.rb
  203. This recipe provides an Ohai plugin as a template. It is included by
  204. both the `default` and `source` recipes.
  205. ## authorized_ips.rb
  206. Sets up configuration for the `authorized_ip` nginx module.
  207. ## source.rb
  208. This recipe is responsible for building Nginx from source. It ensures
  209. that the required packages to build Nginx are installed (pcre,
  210. openssl, compile tools). The source will be downloaded from the
  211. `node['nginx']['source']['url']`. The `node['nginx']['user']` will be
  212. created as a system user. The appropriate configuration and log
  213. directories and config files will be created as well according to the
  214. attributes `node['nginx']['dir']` and 'node['nginx']['log_dir']`.
  215. The recipe attempts to detect whether additional modules should be
  216. added to the configure command through recipe inclusion (see below),
  217. and whether the version or configuration flags have changed and should
  218. trigger a recompile.
  219. The nginx service will be set up according to
  220. `node['nginx']['init_style']`. Available options are:
  221. * runit: uses runit cookbook and sets up `runit_service`.
  222. * bluepill: uses bluepill cookbook and sets up `bluepill_service`.
  223. * anything else (e.g., "init") will use the nginx init script
  224. template.
  225. **RHEL/CentOS** This recipe should work on RHEL/CentOS with "init" as
  226. the init style.
  227. The following recipes are used to build module support into Nginx. To
  228. use a module in the `nginx::source` recipe, add its recipe name to the
  229. attribute `node['nginx']['source']['modules']`.
  230. * `ipv6.rb` - enables IPv6 support
  231. * `http_echo_module.rb` - downloads the `http_echo_module` module and
  232. enables it as a module when compiling nginx.
  233. * `http_geoip_module.rb` - installs the GeoIP libraries and data files
  234. and enables the module for compilation.
  235. * `http_gzip_static_module.rb` - enables the module for compilation.
  236. * `http_realip_module.rb` - enables the module for compilation and
  237. creates the configuration.
  238. * `http_ssl_module.rb` - enables SSL for compilation.
  239. * `http_stub_status_module.rb` - provides `nginx_status` configuration
  240. and enables the module for compilation.
  241. * `naxsi_module` - enables the naxsi module for the web application
  242. firewall for nginx.
  243. * `passenger` - builds the passenger gem and configuration for
  244. "`mod_passenger`".
  245. * `upload_progress_module.rb` - builds the `upload_progress` module
  246. and enables it as a module when compiling nginx.
  247. Adding New Modules
  248. ------------------
  249. To add a new module to be compiled into nginx in the source recipe,
  250. the node's run state is manipulated in a recipe, and the module as a
  251. recipe should be added to `node['nginx']['source']['modules']`. For
  252. example:
  253. node.run_state['nginx_configure_flags'] =
  254. node.run_state['nginx_configure_flags'] | ["--with-http_stub_status_module"]
  255. The recipe will be included by `recipe[nginx::source]` automatically,
  256. adding the configure flags. Add any other configuration templates or
  257. other resources as required. See the recipes described above for
  258. examples.
  259. Ohai Plugin
  260. ===========
  261. The `ohai_plugin` recipe includes an Ohai plugin. It will be
  262. automatically installed and activated, providing the following
  263. attributes via ohai, no matter how nginx is installed (source or
  264. package):
  265. * `node['nginx']['version']` - version of nginx
  266. * `node['nginx']['configure_arguments']` - options passed to
  267. ./configure when nginx was built
  268. * `node['nginx']['prefix']` - installation prefix
  269. * `node['nginx']['conf_path']` - configuration file path
  270. In the source recipe, it is used to determine whether control
  271. attributes for building nginx have changed.
  272. Usage
  273. =====
  274. Include the recipe on your node or role that fits how you wish to
  275. install Nginx on your system per the recipes section above. Modify the
  276. attributes as required in your role to change how various
  277. configuration is applied per the attributes section above. In general,
  278. override attributes in the role should be used when changing
  279. attributes.
  280. There's some redundancy in that the config handling hasn't been
  281. separated from the installation method (yet), so use only one of the
  282. recipes, default or source.
  283. License and Author
  284. ==================
  285. - Author:: Joshua Timberman (<joshua@opscode.com>)
  286. - Author:: Adam Jacob (<adam@opscode.com>)
  287. - Author:: AJ Christensen (<aj@opscode.com>)
  288. - Author:: Jamie Winsor (<jamie@vialstudios.com>)
  289. - Copyright:: 2008-2012, Opscode, Inc
  290. Licensed under the Apache License, Version 2.0 (the "License");
  291. you may not use this file except in compliance with the License.
  292. You may obtain a copy of the License at
  293. http://www.apache.org/licenses/LICENSE-2.0
  294. Unless required by applicable law or agreed to in writing, software
  295. distributed under the License is distributed on an "AS IS" BASIS,
  296. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  297. See the License for the specific language governing permissions and
  298. limitations under the License.