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

@ -14,6 +14,8 @@
# [*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
# [*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 # [*option*] - Reserved for future use
# #
# Actions: # Actions:
@ -27,6 +29,21 @@
# 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,
@ -39,6 +56,8 @@ define nginx::resource::location(
$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

@ -50,6 +50,8 @@ define nginx::resource::vhost(
$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 {
@ -94,6 +96,17 @@ define nginx::resource::vhost(
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 -%>
} }