Merge pull request #233 from abraham1901/dev
Fixed long names virtual hosts...
This commit is contained in:
commit
d1dc560a37
9 changed files with 131 additions and 22 deletions
|
@ -165,3 +165,71 @@ nginx::resource::vhost { 'puppet':
|
|||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Example puppet class calling nginx::vhost with HTTPS FastCGI and redirection of HTTP
|
||||
|
||||
```puppet
|
||||
|
||||
$full_web_path = '/var/www'
|
||||
|
||||
define web::nginx_ssl_with_redirect (
|
||||
$backend_port = 9000,
|
||||
$php = true,
|
||||
$proxy = undef,
|
||||
$www_root = "${full_web_path}/${name}/",
|
||||
$location_cfg_append = undef,
|
||||
) {
|
||||
nginx::resource::vhost { "${name}.${::domain}":
|
||||
ensure => present,
|
||||
www_root => "${full_web_path}/${name}/",
|
||||
location_cfg_append => { 'rewrite' => '^ https://$server_name$request_uri? permanent' },
|
||||
}
|
||||
|
||||
if !$www_root {
|
||||
$tmp_www_root = undef
|
||||
} else {
|
||||
$tmp_www_root = $www_root
|
||||
}
|
||||
|
||||
nginx::resource::vhost { "${name}.${::domain} ${name}":
|
||||
ensure => present,
|
||||
listen_port => 443,
|
||||
www_root => $tmp_www_root,
|
||||
proxy => $proxy,
|
||||
location_cfg_append => $location_cfg_append,
|
||||
index_files => [ 'index.php' ],
|
||||
ssl => true,
|
||||
ssl_cert => 'puppet:///modules/sslkey/whildcard_mydomain.crt',
|
||||
ssl_key => 'puppet:///modules/sslkey/whildcard_mydomain.key',
|
||||
}
|
||||
|
||||
|
||||
if $php {
|
||||
nginx::resource::location { "${name}_root":
|
||||
ensure => present,
|
||||
ssl => true,
|
||||
ssl_only => true,
|
||||
vhost => "${name}.${::domain} ${name}",
|
||||
www_root => "${full_web_path}/${name}/",
|
||||
location => '~ \.php$',
|
||||
index_files => ['index.php', 'index.html', 'index.htm'],
|
||||
proxy => undef,
|
||||
fastcgi => "127.0.0.1:${backend_port}",
|
||||
fastcgi_script => undef,
|
||||
location_cfg_append => {
|
||||
fastcgi_connect_timeout => '3m',
|
||||
fastcgi_read_timeout => '3m',
|
||||
fastcgi_send_timeout => '3m'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# Call class web::nginx_ssl_with_redirect
|
||||
|
||||
```puppet
|
||||
web::nginx_ssl_with_redirect { 'sub-domain-name':
|
||||
backend_port => 9001,
|
||||
}
|
||||
```
|
||||
|
|
|
@ -40,6 +40,12 @@
|
|||
# [*location_cfg_prepend*] - Expects a hash with extra directives to put
|
||||
# before anything else inside location (used with all other types except
|
||||
# custom_cfg)
|
||||
# [*location_custom_cfg_prepend*] - Expects a array with extra directives
|
||||
# to put before anything else inside location (used with all other types
|
||||
# except custom_cfg). Used for logical structures such as if.
|
||||
# [*location_custom_cfg_append*] - Expects a array with extra directives
|
||||
# to put before anything else inside location (used with all other types
|
||||
# except custom_cfg). Used for logical structures such as if.
|
||||
# [*location_cfg_append*] - Expects a hash with extra directives to put
|
||||
# after everything else inside location (used with all other types except
|
||||
# custom_cfg)
|
||||
|
@ -114,6 +120,8 @@ define nginx::resource::location (
|
|||
$location_custom_cfg = undef,
|
||||
$location_cfg_prepend = undef,
|
||||
$location_cfg_append = undef,
|
||||
$location_custom_cfg_prepend = undef,
|
||||
$location_custom_cfg_append = undef,
|
||||
$try_files = undef,
|
||||
$proxy_cache = false,
|
||||
$proxy_cache_valid = false,
|
||||
|
@ -218,7 +226,9 @@ define nginx::resource::location (
|
|||
'absent' => absent,
|
||||
default => file,
|
||||
}
|
||||
$config_file = "${nginx::config::nx_conf_dir}/sites-available/${vhost}.conf"
|
||||
|
||||
$vhost_sanitized = regsubst($vhost, ' ', '_', 'G')
|
||||
$config_file = "${nginx::config::nx_conf_dir}/sites-available/${vhost_sanitized}.conf"
|
||||
|
||||
$location_sanitized_tmp = regsubst($location, '\/', '_', 'G')
|
||||
$location_sanitized = regsubst($location_sanitized_tmp, '\\', '_', 'G')
|
||||
|
@ -259,7 +269,7 @@ define nginx::resource::location (
|
|||
|
||||
## Create stubs for vHost File Fragment Pattern
|
||||
if ($ssl_only != true) {
|
||||
concat::fragment { "${vhost}-${priority}-${location_sanitized}":
|
||||
concat::fragment { "${vhost_sanitized}-${priority}-${location_sanitized}":
|
||||
target => $config_file,
|
||||
content => $content_real,
|
||||
order => "${priority}",
|
||||
|
@ -269,7 +279,7 @@ define nginx::resource::location (
|
|||
## Only create SSL Specific locations if $ssl is true.
|
||||
if ($ssl == true) {
|
||||
$ssl_priority = $priority + 300
|
||||
concat::fragment {"${vhost}-${ssl_priority}-${location_sanitized}-ssl":
|
||||
concat::fragment {"${vhost_sanitized}-${ssl_priority}-${location_sanitized}-ssl":
|
||||
target => $config_file,
|
||||
content => $content_real,
|
||||
order => "${ssl_priority}",
|
||||
|
|
|
@ -538,6 +538,18 @@ describe 'nginx::resource::location' do
|
|||
|
||||
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot define both directory and proxy in a virtual host/) }
|
||||
end
|
||||
|
||||
context 'when vhost name is sanitized' do
|
||||
let :title do 'www.rspec-location.com' end
|
||||
let :params do {
|
||||
:vhost => 'www rspec-vhost com',
|
||||
:www_root => '/',
|
||||
:ssl => true,
|
||||
} end
|
||||
|
||||
it { should contain_concat__fragment("www_rspec-vhost_com-500-www.rspec-location.com").with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
|
||||
it { should contain_concat__fragment("www_rspec-vhost_com-800-www.rspec-location.com-ssl").with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -600,6 +600,13 @@ describe 'nginx::resource::vhost' do
|
|||
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
|
||||
it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
|
||||
end
|
||||
|
||||
context 'when vhost name is sanitized' do
|
||||
let :title do 'www rspec-vhost com' end
|
||||
let :params do default_params end
|
||||
|
||||
it { should contain_concat('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<% if @location_deny -%><% @location_deny.each do |deny_rule| -%>
|
||||
deny <%= deny_rule %>;
|
||||
<% end -%><% end -%>
|
||||
<% if @location_custom_cfg_prepend -%><% @location_custom_cfg_prepend.each do |value| -%>
|
||||
<%= value %>
|
||||
<% end -%><% end -%>
|
||||
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
|
@ -31,5 +34,8 @@
|
|||
<% end -%>
|
||||
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
|
||||
<%= value %>
|
||||
<% end -%><% end -%>
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
<% if @location_custom_cfg_prepend -%><% @location_custom_cfg_prepend.each do |value| -%>
|
||||
<%= value %>
|
||||
<% end -%><% end -%>
|
||||
<% if defined? @www_root -%>
|
||||
root <%= @www_root %>;
|
||||
<% end -%>
|
||||
|
@ -18,6 +21,9 @@
|
|||
<% end -%>
|
||||
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
|
||||
<%= key %> <%= value %>;
|
||||
<% end -%><% end -%>
|
||||
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
|
||||
<%= value %>
|
||||
<% end -%><% end -%>
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
include nginx
|
||||
|
||||
nginx::resource::vhost { 'test.local':
|
||||
nginx::resource::vhost { 'test.local test':
|
||||
ensure => present,
|
||||
ipv6_enable => true,
|
||||
proxy => 'http://proxypass',
|
||||
|
@ -9,7 +9,7 @@ nginx::resource::vhost { 'test.local':
|
|||
nginx::resource::vhost { 'test.local:8080':
|
||||
ensure => present,
|
||||
listen_port => 8080,
|
||||
server_name => 'test.local',
|
||||
server_name => ['test.local test'],
|
||||
ipv6_enable => true,
|
||||
proxy => 'http://proxypass',
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
include nginx
|
||||
|
||||
nginx::resource::vhost { 'test2.local':
|
||||
ensure => present,
|
||||
www_root => '/var/www/nginx-default',
|
||||
ssl => 'true',
|
||||
ssl_cert => '/tmp/server.crt',
|
||||
ssl_key => '/tmp/server.pem',
|
||||
}
|
||||
|
||||
nginx::resource::location { 'test2.local-bob':
|
||||
ensure => present,
|
||||
www_root => '/var/www/bob',
|
||||
location => '/bob',
|
||||
vhost => 'test2.local',
|
||||
}
|
||||
|
17
tests/vhost_ssl.pp
Normal file
17
tests/vhost_ssl.pp
Normal file
|
@ -0,0 +1,17 @@
|
|||
include nginx
|
||||
|
||||
nginx::resource::vhost { 'test2.local test2':
|
||||
ensure => present,
|
||||
www_root => '/var/www/nginx-default',
|
||||
ssl => true,
|
||||
ssl_cert => 'puppet:///modules/sslkey/whildcard_mydomain.crt',
|
||||
ssl_key => 'puppet:///modules/sslkey/whildcard_mydomain.key'
|
||||
}
|
||||
|
||||
nginx::resource::location { 'test2.local-bob':
|
||||
ensure => present,
|
||||
www_root => '/var/www/bob',
|
||||
location => '/bob',
|
||||
vhost => 'test2.local test2',
|
||||
}
|
||||
|
Loading…
Reference in a new issue