2011-06-07 01:05:27 +02:00
|
|
|
# define: nginx::resource::location
|
|
|
|
#
|
|
|
|
# This definition creates a new location entry within a virtual host
|
|
|
|
#
|
|
|
|
# Parameters:
|
2012-10-03 01:35:52 +02:00
|
|
|
# [*ensure*] - Enables or disables the specified location (present|absent)
|
|
|
|
# [*vhost*] - Defines the default vHost for this location entry to include with
|
|
|
|
# [*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
|
|
|
|
# [*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
|
|
|
|
# with nginx::resource::upstream
|
|
|
|
# [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds
|
|
|
|
# [*ssl*] - Indicates whether to setup SSL bindings for this location.
|
2012-10-18 15:33:07 +02:00
|
|
|
# [*ssl_only*] - Required if the SSL and normal vHost have the same port.
|
2012-10-03 01:35:52 +02:00
|
|
|
# [*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
|
|
|
|
# [*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
|
2012-11-08 19:09:49 +01:00
|
|
|
# [*try_files*] - An array of file locations to try
|
2012-10-03 01:35:52 +02:00
|
|
|
# [*option*] - Reserved for future use
|
2011-06-07 01:05:27 +02:00
|
|
|
#
|
|
|
|
# Actions:
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
#
|
|
|
|
# Sample Usage:
|
|
|
|
# nginx::resource::location { 'test2.local-bob':
|
|
|
|
# ensure => present,
|
|
|
|
# www_root => '/var/www/bob',
|
|
|
|
# location => '/bob',
|
|
|
|
# vhost => 'test2.local',
|
|
|
|
# }
|
2012-10-03 01:35:52 +02:00
|
|
|
#
|
|
|
|
# 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,
|
|
|
|
# }
|
2012-08-27 20:18:50 +02:00
|
|
|
|
2011-06-15 21:40:42 +02:00
|
|
|
define nginx::resource::location(
|
2012-10-03 01:35:52 +02:00
|
|
|
$ensure = present,
|
|
|
|
$vhost = undef,
|
|
|
|
$www_root = undef,
|
|
|
|
$index_files = ['index.html', 'index.htm', 'index.php'],
|
|
|
|
$proxy = undef,
|
|
|
|
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
|
|
|
|
$ssl = false,
|
2012-10-18 15:33:07 +02:00
|
|
|
$ssl_only = false,
|
2012-10-03 01:35:52 +02:00
|
|
|
$location_alias = undef,
|
|
|
|
$option = undef,
|
|
|
|
$stub_status = undef,
|
|
|
|
$location_cfg_prepend = undef,
|
|
|
|
$location_cfg_append = undef,
|
2012-11-08 19:09:49 +01:00
|
|
|
$try_files = undef,
|
2011-06-15 21:40:42 +02:00
|
|
|
$location
|
|
|
|
) {
|
|
|
|
File {
|
|
|
|
owner => 'root',
|
|
|
|
group => 'root',
|
|
|
|
mode => '0644',
|
|
|
|
notify => Class['nginx::service'],
|
|
|
|
}
|
|
|
|
|
|
|
|
## Shared Variables
|
|
|
|
$ensure_real = $ensure ? {
|
|
|
|
'absent' => absent,
|
|
|
|
default => file,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Use proxy template if $proxy is defined, otherwise use directory template.
|
|
|
|
if ($proxy != undef) {
|
|
|
|
$content_real = template('nginx/vhost/vhost_location_proxy.erb')
|
2012-09-24 17:21:35 +02:00
|
|
|
} elsif ($location_alias != undef) {
|
|
|
|
$content_real = template('nginx/vhost/vhost_location_alias.erb')
|
2012-10-03 00:44:47 +02:00
|
|
|
} elsif ($stub_status != undef) {
|
|
|
|
$content_real = template('nginx/vhost/vhost_location_stub_status.erb')
|
2011-06-15 21:40:42 +02:00
|
|
|
} else {
|
|
|
|
$content_real = template('nginx/vhost/vhost_location_directory.erb')
|
|
|
|
}
|
|
|
|
|
|
|
|
## Check for various error condtiions
|
|
|
|
if ($vhost == undef) {
|
|
|
|
fail('Cannot create a location reference without attaching to a virtual host')
|
|
|
|
}
|
2012-10-03 00:44:47 +02:00
|
|
|
if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) ) {
|
|
|
|
fail('Cannot create a location reference without a www_root, proxy, location_alias or stub_status defined')
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
if (($www_root != undef) and ($proxy != undef)) {
|
|
|
|
fail('Cannot define both directory and proxy in a virtual host')
|
|
|
|
}
|
|
|
|
|
|
|
|
## Create stubs for vHost File Fragment Pattern
|
2012-10-18 15:33:07 +02:00
|
|
|
if ($ssl_only != 'true') {
|
|
|
|
file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-500-${name}":
|
|
|
|
ensure => $ensure_real,
|
|
|
|
content => $content_real,
|
|
|
|
}
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
## Only create SSL Specific locations if $ssl is true.
|
|
|
|
if ($ssl == 'true') {
|
|
|
|
file {"${nginx::config::nx_temp_dir}/nginx.d/${vhost}-800-${name}-ssl":
|
|
|
|
ensure => $ensure_real,
|
|
|
|
content => $content_real,
|
2011-06-07 00:25:04 +02:00
|
|
|
}
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
}
|