Merge pull request #29 from guruHub/pull_feature_location_cfg

Pull feature location cfg
This commit is contained in:
James Fryman 2012-10-03 11:37:41 -07:00
commit a6d82bffd0
6 changed files with 100 additions and 45 deletions

View file

@ -3,18 +3,20 @@
# This definition creates a new location entry within a virtual host # This definition creates a new location entry within a virtual host
# #
# Parameters: # Parameters:
# [*ensure*] - Enables or disables the specified location (present|absent) # [*ensure*] - Enables or disables the specified location (present|absent)
# [*vhost*] - Defines the default vHost for this location entry to include with # [*vhost*] - Defines the default vHost for this location entry to include with
# [*location*] - Specifies the URI associated with this location entry # [*location*] - Specifies the URI associated with this location entry
# [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy # [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy
# [*index_files*] - Default index files for NGINX to read when traversing a directory # [*index_files*] - Default index files for NGINX to read when traversing a directory
# [*proxy*] - Proxy server(s) for a location to connect to. Accepts a single value, can be used in conjunction # [*proxy*] - Proxy server(s) for a location to connect to. Accepts a single value, can be used in conjunction
# with nginx::resource::upstream # with nginx::resource::upstream
# [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds # [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds
# [*ssl*] - Indicates whether to setup SSL bindings for this location. # [*ssl*] - Indicates whether to setup SSL bindings for this location.
# [*location_alias*] - Path to be used as basis for serving requests for this location # [*location_alias*] - Path to be used as basis for serving requests for this location
# [*stub_status*] - If true it will point configure module stub_status to provide nginx stats on location # [*stub_status*] - If true it will point configure module stub_status to provide nginx stats on location
# [*option*] - Reserved for future use # [*location_cfg_prepend*] - It expects a hash with custom directives to put before anything else inside location
# [*location_cfg_append*] - It expects a hash with custom directives to put after everything else inside location
# [*option*] - Reserved for future use
# #
# Actions: # Actions:
# #
@ -27,18 +29,35 @@
# location => '/bob', # location => '/bob',
# vhost => 'test2.local', # vhost => 'test2.local',
# } # }
#
# Custom config example to limit location on localhost,
# create a hash with any extra custom config you want.
# $my_config = {
# 'access_log' => 'off',
# 'allow' => '127.0.0.1',
# 'deny' => 'all'
# }
# nginx::resource::location { 'test2.local-bob':
# ensure => present,
# www_root => '/var/www/bob',
# location => '/bob',
# vhost => 'test2.local',
# location_cfg_append => $my_config,
# }
define nginx::resource::location( define nginx::resource::location(
$ensure = present, $ensure = present,
$vhost = undef, $vhost = undef,
$www_root = undef, $www_root = undef,
$index_files = ['index.html', 'index.htm', 'index.php'], $index_files = ['index.html', 'index.htm', 'index.php'],
$proxy = undef, $proxy = undef,
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout, $proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
$ssl = false, $ssl = false,
$location_alias = undef, $location_alias = undef,
$option = undef, $option = undef,
$stub_status = undef, $stub_status = undef,
$location_cfg_prepend = undef,
$location_cfg_append = undef,
$location $location
) { ) {
File { File {

View file

@ -35,21 +35,23 @@
# ssl_key => '/tmp/server.pem', # ssl_key => '/tmp/server.pem',
# } # }
define nginx::resource::vhost( define nginx::resource::vhost(
$ensure = 'enable', $ensure = 'enable',
$listen_ip = '*', $listen_ip = '*',
$listen_port = '80', $listen_port = '80',
$ipv6_enable = false, $ipv6_enable = false,
$ipv6_listen_ip = '::', $ipv6_listen_ip = '::',
$ipv6_listen_port = '80', $ipv6_listen_port = '80',
$ssl = false, $ssl = false,
$ssl_cert = undef, $ssl_cert = undef,
$ssl_key = undef, $ssl_key = undef,
$proxy = undef, $proxy = undef,
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout, $proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
$index_files = ['index.html', 'index.htm', 'index.php'], $index_files = ['index.html', 'index.htm', 'index.php'],
$server_name = [$name], $server_name = [$name],
$www_root = undef, $www_root = undef,
$rewrite_www_to_non_www = false, $rewrite_www_to_non_www = false,
$location_cfg_prepend = undef,
$location_cfg_append = undef,
) { ) {
File { File {
@ -84,16 +86,27 @@ define nginx::resource::vhost(
# Create the default location reference for the vHost # Create the default location reference for the vHost
nginx::resource::location {"${name}-default": nginx::resource::location {"${name}-default":
ensure => $ensure, ensure => $ensure,
vhost => $name, vhost => $name,
ssl => $ssl, ssl => $ssl,
location => '/', location => '/',
proxy => $proxy, proxy => $proxy,
proxy_read_timeout => $proxy_read_timeout, proxy_read_timeout => $proxy_read_timeout,
www_root => $www_root, www_root => $www_root,
notify => Class['nginx::service'], notify => Class['nginx::service'],
} }
# Support location_cfg_prepend and location_cfg_append on default location created by vhost
if $location_cfg_prepend {
Nginx::Resource::Location["${name}-default"] {
location_cfg_prepend => $location_cfg_prepend
}
}
if $location_cfg_append {
Nginx::Resource::Location["${name}-default"] {
location_cfg_append => $location_cfg_append
}
}
# Create a proper file close stub. # Create a proper file close stub.
file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699": file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699":
ensure => $ensure ? { ensure => $ensure ? {

View file

@ -1,3 +1,9 @@
location <%= location %> { location <%= location %> {
<% if @location_cfg_prepend -%<% location_cfg_prepend.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
alias <%= location_alias %>; alias <%= location_alias %>;
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
} }

View file

@ -1,4 +1,10 @@
location <%= location %> { location <%= location %> {
<% if @location_cfg_prepend -%><% location_cfg_prepend.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
root <%= www_root %>; root <%= www_root %>;
index <% index_files.each do |i| %> <%= i %> <% end %>; index <% index_files.each do |i| %> <%= i %> <% end %>;
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
} }

View file

@ -1,5 +1,10 @@
location <%= location %> { location <%= location %> {
<% if @location_cfg_prepend -%><% location_cfg_prepend.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
proxy_pass <%= proxy %>; proxy_pass <%= proxy %>;
proxy_read_timeout <%= proxy_read_timeout %>; proxy_read_timeout <%= proxy_read_timeout %>;
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
} }

View file

@ -1,3 +1,9 @@
location <%= location %> { location <%= location %> {
<% if @location_cfg_prepend -%><% location_cfg_prepend.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
stub_status on; stub_status on;
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
} }