James,
This is the best way I found to tackle the problem of custom directives, trying to avoid common usage of module involve hacking the module/template to be able place custom directives. Right now support was added only for location context (default and custom ones), it expects a hash with key value and it's supported on all current location types. Added an example inside location.pp, usage it's pretty easy.
This commit is contained in:
parent
a9273d7fb8
commit
49beb91993
6 changed files with 100 additions and 45 deletions
|
@ -3,18 +3,20 @@
|
|||
# This definition creates a new location entry within a virtual host
|
||||
#
|
||||
# Parameters:
|
||||
# [*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.
|
||||
# [*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
|
||||
# [*option*] - Reserved for future use
|
||||
# [*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.
|
||||
# [*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
|
||||
# [*option*] - Reserved for future use
|
||||
#
|
||||
# Actions:
|
||||
#
|
||||
|
@ -27,18 +29,35 @@
|
|||
# location => '/bob',
|
||||
# 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(
|
||||
$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,
|
||||
$location_alias = undef,
|
||||
$option = undef,
|
||||
$stub_status = undef,
|
||||
$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,
|
||||
$location_alias = undef,
|
||||
$option = undef,
|
||||
$stub_status = undef,
|
||||
$location_cfg_prepend = undef,
|
||||
$location_cfg_append = undef,
|
||||
$location
|
||||
) {
|
||||
File {
|
||||
|
|
|
@ -35,21 +35,23 @@
|
|||
# ssl_key => '/tmp/server.pem',
|
||||
# }
|
||||
define nginx::resource::vhost(
|
||||
$ensure = 'enable',
|
||||
$listen_ip = '*',
|
||||
$listen_port = '80',
|
||||
$ipv6_enable = false,
|
||||
$ipv6_listen_ip = '::',
|
||||
$ipv6_listen_port = '80',
|
||||
$ssl = false,
|
||||
$ssl_cert = undef,
|
||||
$ssl_key = undef,
|
||||
$proxy = undef,
|
||||
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
|
||||
$index_files = ['index.html', 'index.htm', 'index.php'],
|
||||
$server_name = [$name],
|
||||
$www_root = undef,
|
||||
$ensure = 'enable',
|
||||
$listen_ip = '*',
|
||||
$listen_port = '80',
|
||||
$ipv6_enable = false,
|
||||
$ipv6_listen_ip = '::',
|
||||
$ipv6_listen_port = '80',
|
||||
$ssl = false,
|
||||
$ssl_cert = undef,
|
||||
$ssl_key = undef,
|
||||
$proxy = undef,
|
||||
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
|
||||
$index_files = ['index.html', 'index.htm', 'index.php'],
|
||||
$server_name = [$name],
|
||||
$www_root = undef,
|
||||
$rewrite_www_to_non_www = false,
|
||||
$location_cfg_prepend = undef,
|
||||
$location_cfg_append = undef,
|
||||
) {
|
||||
|
||||
File {
|
||||
|
@ -84,16 +86,27 @@ define nginx::resource::vhost(
|
|||
|
||||
# Create the default location reference for the vHost
|
||||
nginx::resource::location {"${name}-default":
|
||||
ensure => $ensure,
|
||||
vhost => $name,
|
||||
ssl => $ssl,
|
||||
location => '/',
|
||||
proxy => $proxy,
|
||||
proxy_read_timeout => $proxy_read_timeout,
|
||||
www_root => $www_root,
|
||||
notify => Class['nginx::service'],
|
||||
ensure => $ensure,
|
||||
vhost => $name,
|
||||
ssl => $ssl,
|
||||
location => '/',
|
||||
proxy => $proxy,
|
||||
proxy_read_timeout => $proxy_read_timeout,
|
||||
www_root => $www_root,
|
||||
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.
|
||||
file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699":
|
||||
ensure => $ensure ? {
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
location <%= location %> {
|
||||
<% if @location_cfg_prepend -%<% location_cfg_prepend.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
alias <%= location_alias %>;
|
||||
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
}
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
location <%= location %> {
|
||||
<% if @location_cfg_prepend -%><% location_cfg_prepend.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
root <%= www_root %>;
|
||||
index <% index_files.each do |i| %> <%= i %> <% end %>;
|
||||
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
location <%= location %> {
|
||||
<% if @location_cfg_prepend -%><% location_cfg_prepend.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
proxy_pass <%= proxy %>;
|
||||
proxy_read_timeout <%= proxy_read_timeout %>;
|
||||
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
location <%= location %> {
|
||||
<% if @location_cfg_prepend -%><% location_cfg_prepend.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
stub_status on;
|
||||
<% if @location_cfg_append -%><% location_cfg_append.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue