Skip to content

Commit 0b0a226

Browse files
committed
Merge pull request #901 from antaflos/consolidate_alias_scriptalias
Allow specifying all alias directives in `aliases`
2 parents 83476d4 + 7897f37 commit 0b0a226

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,20 +898,31 @@ Specifies paths to additional static, vhost-specific Apache configuration files.
898898

899899
#####`aliases`
900900

901-
Passes a list of hashes to the vhost to create Alias or AliasMatch directives as per the [mod_alias documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). These hashes are formatted as follows:
901+
Passes a list of hashes to the vhost to create Alias, AliasMatch, ScriptAlias or ScriptAliasMatch directives as per the [mod_alias documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). These hashes are formatted as follows:
902902

903903
```puppet
904904
aliases => [
905-
{ aliasmatch => '^/image/(.*)\.jpg$',
906-
path => '/files/jpg.images/$1.jpg',
905+
{ aliasmatch => '^/image/(.*)\.jpg$',
906+
path => '/files/jpg.images/$1.jpg',
907907
}
908-
{ alias => '/image',
909-
path => '/ftp/pub/image',
908+
{ alias => '/image',
909+
path => '/ftp/pub/image',
910+
},
911+
{ scriptaliasmatch => '^/cgi-bin(.*)',
912+
path => '/usr/local/share/cgi-bin$1',
913+
},
914+
{ scriptalias => '/nagios/cgi-bin/',
915+
path => '/usr/lib/nagios/cgi-bin/',
916+
},
917+
{ alias => '/nagios',
918+
path => '/usr/share/nagios/html',
910919
},
911920
],
912921
```
913922

914-
For `alias` and `aliasmatch` to work, each needs a corresponding context, such as '< Directory /path/to/directory>' or '<Location /path/to/directory>'. The Alias and AliasMatch directives are created in the order specified in the `aliases` parameter. As described in the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html), more specific `alias` or `aliasmatch` parameters should come before the more general ones to avoid shadowing.
923+
For `alias`, `aliasmatch`, `scriptalias` and `scriptaliasmatch` to work, each needs a corresponding context, such as `<Directory /path/to/directory>` or `<Location /some/location/here>`. The directives are created in the order specified in the `aliases` parameter. As described in the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html), more specific `alias`, `aliasmatch`, `scriptalias` or `scriptaliasmatch` parameters should come before the more general ones to avoid shadowing.
924+
925+
*Note*: Using the `aliases` parameter is preferred over the `scriptaliases` parameter since here the order of the various alias directives among each other can be controlled precisely. Defining ScriptAliases using the `scriptaliases` parameter means *all* ScriptAlias directives will come after *all* Alias directives, which can lead to Alias directives shadowing ScriptAlias directives. This is often problematic, for example in case of Nagios.
915926

916927
*Note:* If `apache::mod::passenger` is loaded and `PassengerHighPerformance => true` is set, then Alias might have issues honoring the `PassengerEnabled => off` statement. See [this article](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) for details.
917928

@@ -1266,6 +1277,8 @@ Defines a directory of CGI scripts to be aliased to the path '/cgi-bin', for exa
12661277

12671278
#####`scriptaliases`
12681279

1280+
*Note*: This parameter is deprecated in favour of the `aliases` parameter.
1281+
12691282
Passes an array of hashes to the vhost to create either ScriptAlias or ScriptAliasMatch statements as per the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). These hashes are formatted as follows:
12701283

12711284
```puppet

spec/acceptance/vhost_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,10 @@ class { 'apache': }
768768
host { 'test.server': ip => '127.0.0.1' }
769769
apache::vhost { 'test.server':
770770
docroot => '/tmp',
771-
aliases => [{ alias => '/image', path => '/ftp/pub/image' }],
771+
aliases => [
772+
{ alias => '/image' , path => '/ftp/pub/image' } ,
773+
{ scriptalias => '/myscript' , path => '/usr/share/myscript' }
774+
],
772775
}
773776
EOS
774777
apply_manifest(pp, :catch_failures => true)
@@ -777,6 +780,7 @@ class { 'apache': }
777780
describe file("#{$vhost_dir}/25-test.server.conf") do
778781
it { is_expected.to be_file }
779782
it { is_expected.to contain 'Alias /image "/ftp/pub/image"' }
783+
it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' }
780784
end
781785
end
782786

templates/vhost/_aliases.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
Alias <%= alias_statement["alias"] %> "<%= alias_statement["path"] %>"
77
<%- elsif alias_statement["aliasmatch"] and alias_statement["aliasmatch"] != '' -%>
88
AliasMatch <%= alias_statement["aliasmatch"] %> "<%= alias_statement["path"] %>"
9+
<%- elsif alias_statement["scriptalias"] and alias_statement["scriptalias"] != '' -%>
10+
ScriptAlias <%= alias_statement["scriptalias"] %> "<%= alias_statement["path"] %>"
11+
<%- elsif alias_statement["scriptaliasmatch"] and alias_statement["scriptaliasmatch"] != '' -%>
12+
ScriptAliasMatch <%= alias_statement["scriptaliasmatch"] %> "<%= alias_statement["path"] %>"
913
<%- end -%>
1014
<%- end -%>
1115
<%- end -%>

0 commit comments

Comments
 (0)