Skip to content

Commit 4d3702e

Browse files
authored
Merge pull request #2195 from yakatz/bug/docroot_with_vhostalias
Allow `docroot` with `mod_vhost_alias` `virtual_docroot`
2 parents 9fae75a + c1dbcd4 commit 4d3702e

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

REFERENCE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7756,6 +7756,7 @@ The following parameters are available in the `apache::vhost` defined type:
77567756
* [`suphp_engine`](#suphp_engine)
77577757
* [`vhost_name`](#vhost_name)
77587758
* [`virtual_docroot`](#virtual_docroot)
7759+
* [`virtual_use_default_docroot`](#virtual_use_default_docroot)
77597760
* [`wsgi_daemon_process`](#wsgi_daemon_process)
77607761
* [`wsgi_daemon_process_options`](#wsgi_daemon_process_options)
77617762
* [`wsgi_application_group`](#wsgi_application_group)
@@ -9957,6 +9958,8 @@ Data type: `Any`
99579958

99589959
Sets up a virtual host with a wildcard alias subdomain mapped to a directory with the
99599960
same name. For example, `http://example.com` would map to `/var/www/example.com`.
9961+
Note that the `DocumentRoot` directive will not be present even though there is a value
9962+
set for `docroot` in the manifest. See [`virtual_use_default_docroot`](#virtual_use_default_docroot) to change this behavior.
99609963
``` puppet
99619964
apache::vhost { 'subdomain.loc':
99629965
vhost_name => '*',
@@ -9969,6 +9972,25 @@ apache::vhost { 'subdomain.loc':
99699972

99709973
Default value: ``false``
99719974

9975+
##### <a name="virtual_use_default_docroot"></a>`virtual_use_default_docroot`
9976+
9977+
Data type: `Any`
9978+
9979+
By default, when using `virtual_docroot`, the value of `docroot` is ignored. Setting this
9980+
to `true` will mean both directives will be added to the configuration.
9981+
``` puppet
9982+
apache::vhost { 'subdomain.loc':
9983+
vhost_name => '*',
9984+
port => '80',
9985+
virtual_docroot => '/var/www/%-2+',
9986+
docroot => '/var/www',
9987+
virtual_use_default_docroot => true,
9988+
serveraliases => ['*.loc',],
9989+
}
9990+
```
9991+
9992+
Default value: ``false``
9993+
99729994
##### <a name="wsgi_daemon_process"></a>`wsgi_daemon_process`
99739995

99749996
Data type: `Optional[Variant[String,Hash]]`

manifests/vhost.pp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,8 @@
12211221
# @param virtual_docroot
12221222
# Sets up a virtual host with a wildcard alias subdomain mapped to a directory with the
12231223
# same name. For example, `http://example.com` would map to `/var/www/example.com`.
1224+
# Note that the `DocumentRoot` directive will not be present even though there is a value
1225+
# set for `docroot` in the manifest. See [`virtual_use_default_docroot`](#virtual_use_default_docroot) to change this behavior.
12241226
# ``` puppet
12251227
# apache::vhost { 'subdomain.loc':
12261228
# vhost_name => '*',
@@ -1231,6 +1233,20 @@
12311233
# }
12321234
# ```
12331235
#
1236+
# @param virtual_use_default_docroot
1237+
# By default, when using `virtual_docroot`, the value of `docroot` is ignored. Setting this
1238+
# to `true` will mean both directives will be added to the configuration.
1239+
# ``` puppet
1240+
# apache::vhost { 'subdomain.loc':
1241+
# vhost_name => '*',
1242+
# port => '80',
1243+
# virtual_docroot => '/var/www/%-2+',
1244+
# docroot => '/var/www',
1245+
# virtual_use_default_docroot => true,
1246+
# serveraliases => ['*.loc',],
1247+
# }
1248+
# ```
1249+
#
12341250
# @param wsgi_daemon_process
12351251
# Sets up a virtual host with [WSGI](https://github.com/GrahamDumpleton/mod_wsgi) alongside
12361252
# wsgi_daemon_process_options, wsgi_process_group,
@@ -1746,6 +1762,7 @@
17461762
Variant[Boolean,String] $docroot,
17471763
$manage_docroot = true,
17481764
$virtual_docroot = false,
1765+
$virtual_use_default_docroot = false,
17491766
$port = undef,
17501767
$ip = undef,
17511768
Boolean $ip_based = false,
@@ -2429,6 +2446,7 @@
24292446

24302447
# Template uses:
24312448
# - $virtual_docroot
2449+
# - $virtual_use_default_docroot
24322450
# - $docroot
24332451
if $docroot {
24342452
concat::fragment { "${name}-docroot":

spec/defines/vhost_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
'docroot' => '/var/www/foo',
5959
'manage_docroot' => false,
6060
'virtual_docroot' => true,
61+
'virtual_use_default_docroot' => false,
6162
'port' => '8080',
6263
'ip' => '127.0.0.1',
6364
'ip_based' => true,
@@ -1747,6 +1748,48 @@
17471748
it { is_expected.not_to contain_concat__fragment('NameVirtualHost *:80') }
17481749
end
17491750

1751+
context 'vhost with backwards compatible virtual_docroot' do
1752+
let :params do
1753+
{
1754+
'docroot' => '/var/www/html',
1755+
'virtual_docroot' => '/var/www/sites/%0',
1756+
}
1757+
end
1758+
1759+
it { is_expected.to compile }
1760+
it {
1761+
is_expected.to contain_concat__fragment('rspec.example.com-docroot').with(
1762+
content: %r{^\s+VirtualDocumentRoot "/var/www/sites/%0"$},
1763+
)
1764+
}
1765+
it {
1766+
is_expected.not_to contain_concat__fragment('rspec.example.com-docroot').with(
1767+
content: %r{^\s+DocumentRoot "/var/www/html"$},
1768+
)
1769+
}
1770+
end
1771+
context 'vhost with virtual_docroot and docroot' do
1772+
let :params do
1773+
{
1774+
'docroot' => '/var/www/html',
1775+
'virtual_use_default_docroot' => true,
1776+
'virtual_docroot' => '/var/www/sites/%0',
1777+
}
1778+
end
1779+
1780+
it { is_expected.to compile }
1781+
it {
1782+
is_expected.to contain_concat__fragment('rspec.example.com-docroot').with(
1783+
content: %r{^\s+VirtualDocumentRoot "/var/www/sites/%0"$},
1784+
)
1785+
}
1786+
it {
1787+
is_expected.to contain_concat__fragment('rspec.example.com-docroot').with(
1788+
content: %r{^\s+DocumentRoot "/var/www/html"$},
1789+
)
1790+
}
1791+
end
1792+
17501793
context 'modsec_audit_log' do
17511794
let :params do
17521795
{

templates/vhost/_docroot.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Vhost docroot
33
<% if @virtual_docroot -%>
44
VirtualDocumentRoot "<%= @virtual_docroot %>"
5-
<% elsif @docroot -%>
5+
<% end -%>
6+
<% if @docroot and ((not @virtual_docroot) or @virtual_use_default_docroot) -%>
67
DocumentRoot "<%= @docroot %>"
78
<% end -%>

0 commit comments

Comments
 (0)