Add $aliases and $redirect to apache::site, ensure default vhost is loaded first.
This commit is contained in:
parent
bf4ad72690
commit
ced754f674
2 changed files with 41 additions and 21 deletions
|
@ -94,30 +94,40 @@ class apache::server inherits apache::common {
|
|||
#
|
||||
# $name:
|
||||
# FQDN of virtual host.
|
||||
# $aliases:
|
||||
# Optional ServerAlias for this virtual host.
|
||||
# $root:
|
||||
# Path to document root. Defaults to /srv/www/http/$fqdn
|
||||
# $config:
|
||||
# Path to custom configuration file. Defaults to a basic template.
|
||||
# $redirect:
|
||||
# Add redirect to given URL.
|
||||
#
|
||||
# === Sample usage
|
||||
#
|
||||
# apache::site { "default":
|
||||
# redirect => "http://www.example.com/",
|
||||
# }
|
||||
# apache::site { "www.example.com":
|
||||
# root => "/roles/prteam/public/public_access",
|
||||
# config => "puppet:///path/to/www.example.com.conf",
|
||||
# }
|
||||
#
|
||||
define apache::site($root="", $config="") {
|
||||
define apache::site(aliases="", $root="", $config="", $redirect="") {
|
||||
|
||||
if $name == "default" {
|
||||
$site_fqdn = $fqdn
|
||||
$site_conf = "/etc/httpd/site.http.d/00-${site_fqdn}.conf"
|
||||
} else {
|
||||
$site_fqdn = $name
|
||||
$site_conf = "/etc/httpd/site.http.d/10-${site_fqdn}.conf"
|
||||
|
||||
if !$redirect {
|
||||
if $root {
|
||||
file { "/srv/www/http/${site_fqdn}":
|
||||
ensure => link,
|
||||
target => $root,
|
||||
before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"],
|
||||
before => File["${site_conf}"],
|
||||
}
|
||||
} else {
|
||||
file { "/srv/www/http/${site_fqdn}":
|
||||
|
@ -125,7 +135,7 @@ define apache::site($root="", $config="") {
|
|||
mode => 0755,
|
||||
owner => root,
|
||||
group => root,
|
||||
before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"],
|
||||
before => File["${site_conf}"],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,11 +144,12 @@ define apache::site($root="", $config="") {
|
|||
mode => 0755,
|
||||
owner => root,
|
||||
group => root,
|
||||
before => File["/etc/httpd/site.http.d/${site_fqdn}.conf"],
|
||||
before => File["${site_conf}"],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file { "/etc/httpd/site.http.d/${site_fqdn}.conf":
|
||||
file { "${site_conf}":
|
||||
ensure => present,
|
||||
mode => 0644,
|
||||
owner => root,
|
||||
|
@ -147,11 +158,17 @@ define apache::site($root="", $config="") {
|
|||
}
|
||||
|
||||
if $config {
|
||||
File["/etc/httpd/site.http.d/${site_fqdn}.conf"] {
|
||||
File["${site_conf}"] {
|
||||
source => $config,
|
||||
}
|
||||
} else {
|
||||
File["/etc/httpd/site.http.d/${site_fqdn}.conf"] {
|
||||
}
|
||||
if $redirect {
|
||||
File["${site_conf}"] {
|
||||
content => "<VirtualHost *:80>\n ServerName ${site_fqdn}\n Redirect permanent / ${redirect}\n</VirtualHost>\n",
|
||||
}
|
||||
}
|
||||
if !$config and !$redirect {
|
||||
File["${site_conf}"] {
|
||||
content => template("apache/site.http.conf.erb"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<VirtualHost *:80>
|
||||
ServerName <%= site_fqdn %>
|
||||
<% if aliases != "" -%>
|
||||
ServerAlias <%= aliases %>
|
||||
<% end -%>
|
||||
ErrorLog /srv/www/log/http/<%= site_fqdn %>/error_log
|
||||
CustomLog /srv/www/log/http/<%= site_fqdn %>/access_log combined
|
||||
DocumentRoot /srv/www/http/<%= site_fqdn %>
|
||||
|
|
Loading…
Add table
Reference in a new issue