2011-12-13 23:49:18 +01:00
|
|
|
# define: nginx::resource::vhost
|
2011-06-07 01:05:27 +02:00
|
|
|
#
|
2011-12-13 23:49:18 +01:00
|
|
|
# This definition creates a virtual host
|
2011-06-07 01:05:27 +02:00
|
|
|
#
|
|
|
|
# Parameters:
|
2012-09-01 17:46:27 +02:00
|
|
|
# [*ensure*] - Enables or disables the specified vhost (present|absent)
|
|
|
|
# [*listen_ip*] - Default IP Address for NGINX to listen with this vHost on. Defaults to all interfaces (*)
|
|
|
|
# [*listen_port*] - Default IP Port for NGINX to listen with this vHost on. Defaults to TCP 80
|
2012-10-03 23:16:18 +02:00
|
|
|
# [*listen_options*] - Extra options for listen directive like 'default' to catchall. Undef by default.
|
2012-09-01 17:46:27 +02:00
|
|
|
# [*ipv6_enable*] - BOOL value to enable/disable IPv6 support (false|true). Module will check to see if IPv6
|
|
|
|
# support exists on your system before enabling.
|
|
|
|
# [*ipv6_listen_ip*] - Default IPv6 Address for NGINX to listen with this vHost on. Defaults to all interfaces (::)
|
|
|
|
# [*ipv6_listen_port*] - Default IPv6 Port for NGINX to listen with this vHost on. Defaults to TCP 80
|
2012-10-03 23:16:18 +02:00
|
|
|
# [*ipv6_listen_options*] - Extra options for listen directive like 'default' to catchall. Template will allways add ipv6only=on.
|
|
|
|
# While issue jfryman/puppet-nginx#30 is discussed, default value is 'default'.
|
2012-09-01 17:46:27 +02:00
|
|
|
# [*index_files*] - Default index files for NGINX to read when traversing a directory
|
|
|
|
# [*proxy*] - Proxy server(s) for the root location to connect to. Accepts a single value, can be used in
|
|
|
|
# conjunction with nginx::resource::upstream
|
|
|
|
# [*proxy_read_timeout*] - Override the default the proxy read timeout value of 90 seconds
|
2013-03-20 18:44:45 +01:00
|
|
|
# [*fastcgi*] - location of fastcgi (host:port)
|
|
|
|
# [*fastcgi_params*] - optional alternative fastcgi_params file to use
|
|
|
|
# [*fastcgi_script*] - optional SCRIPT_FILE parameter
|
2012-09-01 17:46:27 +02:00
|
|
|
# [*ssl*] - Indicates whether to setup SSL bindings for this vhost.
|
|
|
|
# [*ssl_cert*] - Pre-generated SSL Certificate file to reference for SSL Support. This is not generated by this module.
|
|
|
|
# [*ssl_key*] - Pre-generated SSL Key file to reference for SSL Support. This is not generated by this module.
|
2012-10-18 15:33:07 +02:00
|
|
|
# [*ssl_port*] - Default IP Port for NGINX to listen with this SSL vHost on. Defaults to TCP 443
|
2013-06-27 15:42:38 +02:00
|
|
|
# [*ssl_protocols*] - SSL protocols enabled. Defaults to 'SSLv3 TLSv1 TLSv1.1 TLSv1.2'.
|
|
|
|
# [*ssl_ciphers*] - SSL ciphers enabled. Defaults to 'HIGH:!aNULL:!MD5'.
|
|
|
|
# [*spdy*] - Toggles SPDY protocol.
|
2012-09-27 16:42:53 +02:00
|
|
|
# [*server_name*] - List of vhostnames for which this vhost will respond. Default [$name].
|
2012-09-01 17:46:27 +02:00
|
|
|
# [*www_root*] - Specifies the location on disk for files to be read from. Cannot be set in conjunction with $proxy
|
2013-05-21 15:15:59 +02:00
|
|
|
# [*rewrite_www_to_non_www*] - Adds a server directive and rewrite rule to
|
|
|
|
# rewrite www.domain.com to domain.com in order to avoid duplicate content (SEO);
|
|
|
|
# [*try_files*] - Specifies the locations for files to be
|
|
|
|
# checked as an array. Cannot be used in conjuction with $proxy.
|
|
|
|
# [*proxy_cache*] - This directive sets name of zone for caching.
|
|
|
|
# The same zone can be used in multiple places.
|
|
|
|
# [*proxy_cache_valid*] - This directive sets the time for caching
|
|
|
|
# different replies.
|
|
|
|
# [*auth_basic*] - This directive includes testing name and
|
|
|
|
# password with HTTP Basic Authentication.
|
|
|
|
# [*auth_basic_user_file*] - This directive sets the htpasswd filename for
|
|
|
|
# the authentication realm.
|
|
|
|
# [*vhost_cfg_append*] - It expects a hash with custom directives to
|
|
|
|
# put after everything else inside vhost
|
|
|
|
# [*rewrite_to_https*] - Adds a server directive and rewrite rule to
|
|
|
|
# rewrite to ssl
|
2013-06-13 18:44:15 +02:00
|
|
|
# [*include_files*] - Adds include files to vhost
|
2013-05-21 15:15:59 +02:00
|
|
|
#
|
2011-06-07 01:05:27 +02:00
|
|
|
# Actions:
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
#
|
|
|
|
# Sample Usage:
|
|
|
|
# nginx::resource::vhost { 'test2.local':
|
|
|
|
# ensure => present,
|
|
|
|
# www_root => '/var/www/nginx-default',
|
2013-05-26 14:24:40 +02:00
|
|
|
# ssl => true,
|
2011-06-07 01:05:27 +02:00
|
|
|
# ssl_cert => '/tmp/server.crt',
|
|
|
|
# ssl_key => '/tmp/server.pem',
|
|
|
|
# }
|
2013-04-13 13:52:21 +02:00
|
|
|
define nginx::resource::vhost (
|
2012-10-03 01:35:52 +02:00
|
|
|
$ensure = 'enable',
|
|
|
|
$listen_ip = '*',
|
|
|
|
$listen_port = '80',
|
2012-10-03 23:16:18 +02:00
|
|
|
$listen_options = undef,
|
2012-10-03 01:35:52 +02:00
|
|
|
$ipv6_enable = false,
|
|
|
|
$ipv6_listen_ip = '::',
|
|
|
|
$ipv6_listen_port = '80',
|
2012-10-03 23:16:18 +02:00
|
|
|
$ipv6_listen_options = 'default',
|
2012-10-03 01:35:52 +02:00
|
|
|
$ssl = false,
|
|
|
|
$ssl_cert = undef,
|
|
|
|
$ssl_key = undef,
|
2013-03-16 10:34:07 +01:00
|
|
|
$ssl_port = '443',
|
2013-06-27 15:42:38 +02:00
|
|
|
$ssl_protocols = 'SSLv3 TLSv1 TLSv1.1 TLSv1.2',
|
|
|
|
$ssl_ciphers = 'HIGH:!aNULL:!MD5',
|
|
|
|
$spdy = $nginx::params::nx_spdy,
|
2012-10-03 01:35:52 +02:00
|
|
|
$proxy = undef,
|
|
|
|
$proxy_read_timeout = $nginx::params::nx_proxy_read_timeout,
|
2013-04-24 10:42:06 +02:00
|
|
|
$proxy_set_header = [],
|
2013-05-21 14:30:21 +02:00
|
|
|
$proxy_cache = false,
|
|
|
|
$proxy_cache_valid = false,
|
2013-03-20 18:44:45 +01:00
|
|
|
$fastcgi = undef,
|
|
|
|
$fastcgi_params = '/etc/nginx/fastcgi_params',
|
|
|
|
$fastcgi_script = undef,
|
2013-04-13 13:52:21 +02:00
|
|
|
$index_files = [
|
|
|
|
'index.html',
|
|
|
|
'index.htm',
|
|
|
|
'index.php'],
|
2012-10-03 01:35:52 +02:00
|
|
|
$server_name = [$name],
|
|
|
|
$www_root = undef,
|
2012-09-01 17:46:27 +02:00
|
|
|
$rewrite_www_to_non_www = false,
|
2013-06-13 18:44:15 +02:00
|
|
|
$rewrite_to_https = undef,
|
2013-07-03 22:54:33 +02:00
|
|
|
$location_custom_cfg = undef,
|
2012-10-03 01:35:52 +02:00
|
|
|
$location_cfg_prepend = undef,
|
|
|
|
$location_cfg_append = undef,
|
2013-03-27 19:13:52 +01:00
|
|
|
$try_files = undef,
|
2013-05-20 16:30:32 +02:00
|
|
|
$auth_basic = undef,
|
|
|
|
$auth_basic_user_file = undef,
|
2013-05-21 14:30:21 +02:00
|
|
|
$vhost_cfg_append = undef,
|
2013-06-13 18:44:15 +02:00
|
|
|
$include_files = undef
|
2011-06-07 00:25:04 +02:00
|
|
|
) {
|
2011-06-15 21:40:42 +02:00
|
|
|
|
|
|
|
File {
|
2013-04-13 19:39:52 +02:00
|
|
|
ensure => $ensure ? {
|
|
|
|
'absent' => absent,
|
|
|
|
default => 'file',
|
|
|
|
},
|
|
|
|
notify => Class['nginx::service'],
|
|
|
|
owner => 'root',
|
|
|
|
group => 'root',
|
|
|
|
mode => '0644',
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add IPv6 Logic Check - Nginx service will not start if ipv6 is enabled
|
|
|
|
# and support does not exist for it in the kernel.
|
2013-07-26 10:15:55 +02:00
|
|
|
if ($ipv6_enable == true) and (!$ipaddress6) {
|
2011-06-15 21:40:42 +02:00
|
|
|
warning('nginx: IPv6 support is not enabled or configured properly')
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check to see if SSL Certificates are properly defined.
|
2013-04-13 19:39:52 +02:00
|
|
|
if ($ssl == true) {
|
2011-06-15 21:40:42 +02:00
|
|
|
if ($ssl_cert == undef) or ($ssl_key == undef) {
|
|
|
|
fail('nginx: SSL certificate/key (ssl_cert/ssl_cert) and/or SSL Private must be defined and exist on the target system(s)')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Use the File Fragment Pattern to construct the configuration files.
|
|
|
|
# Create the base configuration file reference.
|
2012-10-18 15:33:07 +02:00
|
|
|
if ($listen_port != $ssl_port) {
|
|
|
|
file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-001":
|
|
|
|
ensure => $ensure ? {
|
|
|
|
'absent' => absent,
|
|
|
|
default => 'file',
|
|
|
|
},
|
|
|
|
content => template('nginx/vhost/vhost_header.erb'),
|
2013-03-27 19:13:52 +01:00
|
|
|
notify => Class['nginx::service'],
|
2012-10-18 15:33:07 +02:00
|
|
|
}
|
|
|
|
}
|
2013-03-16 10:34:07 +01:00
|
|
|
|
2013-05-26 14:24:40 +02:00
|
|
|
if ($ssl == true) and ($ssl_port == $listen_port) {
|
|
|
|
$ssl_only = true
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create the default location reference for the vHost
|
|
|
|
nginx::resource::location {"${name}-default":
|
2012-10-03 01:35:52 +02:00
|
|
|
ensure => $ensure,
|
|
|
|
vhost => $name,
|
|
|
|
ssl => $ssl,
|
2012-10-18 15:33:07 +02:00
|
|
|
ssl_only => $ssl_only,
|
2012-10-03 01:35:52 +02:00
|
|
|
location => '/',
|
|
|
|
proxy => $proxy,
|
|
|
|
proxy_read_timeout => $proxy_read_timeout,
|
2013-05-21 14:30:21 +02:00
|
|
|
proxy_cache => $proxy_cache,
|
|
|
|
proxy_cache_valid => $proxy_cache_valid,
|
2013-03-20 18:44:45 +01:00
|
|
|
fastcgi => $fastcgi,
|
|
|
|
fastcgi_params => $fastcgi_params,
|
|
|
|
fastcgi_script => $fastcgi_script,
|
2012-11-08 19:09:49 +01:00
|
|
|
try_files => $try_files,
|
2012-10-03 01:35:52 +02:00
|
|
|
www_root => $www_root,
|
2013-07-13 07:28:49 +02:00
|
|
|
index_files => $index_files,
|
2013-07-03 22:54:33 +02:00
|
|
|
location_custom_cfg => $location_custom_cfg,
|
2012-10-03 01:35:52 +02:00
|
|
|
notify => Class['nginx::service'],
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 01:35:52 +02:00
|
|
|
# Support location_cfg_prepend and location_cfg_append on default location created by vhost
|
|
|
|
if $location_cfg_prepend {
|
|
|
|
Nginx::Resource::Location["${name}-default"] {
|
2013-04-13 13:52:21 +02:00
|
|
|
location_cfg_prepend => $location_cfg_prepend }
|
2012-10-03 01:35:52 +02:00
|
|
|
}
|
2013-04-13 13:52:21 +02:00
|
|
|
|
2012-10-03 01:35:52 +02:00
|
|
|
if $location_cfg_append {
|
|
|
|
Nginx::Resource::Location["${name}-default"] {
|
2013-04-13 13:52:21 +02:00
|
|
|
location_cfg_append => $location_cfg_append }
|
2012-10-03 01:35:52 +02:00
|
|
|
}
|
2013-04-13 13:52:21 +02:00
|
|
|
|
2011-06-15 21:40:42 +02:00
|
|
|
# Create a proper file close stub.
|
2012-10-18 15:33:07 +02:00
|
|
|
if ($listen_port != $ssl_port) {
|
2013-04-13 19:39:52 +02:00
|
|
|
file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-699": content => template('nginx/vhost/vhost_footer.erb'), }
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create SSL File Stubs if SSL is enabled
|
2013-05-26 14:24:40 +02:00
|
|
|
if ($ssl == true) {
|
2011-06-15 21:40:42 +02:00
|
|
|
file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-700-ssl":
|
2013-06-13 18:44:15 +02:00
|
|
|
ensure => $ensure ? {
|
2012-03-04 18:19:44 +01:00
|
|
|
'absent' => absent,
|
2011-06-15 21:40:42 +02:00
|
|
|
default => 'file',
|
|
|
|
},
|
|
|
|
content => template('nginx/vhost/vhost_ssl_header.erb'),
|
2013-03-27 19:13:52 +01:00
|
|
|
notify => Class['nginx::service'],
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
file { "${nginx::config::nx_temp_dir}/nginx.d/${name}-999-ssl":
|
2013-06-13 18:44:15 +02:00
|
|
|
ensure => $ensure ? {
|
2011-06-15 21:40:42 +02:00
|
|
|
'absent' => absent,
|
2012-03-04 18:19:44 +01:00
|
|
|
default => 'file',
|
2011-06-15 21:40:42 +02:00
|
|
|
},
|
|
|
|
content => template('nginx/vhost/vhost_footer.erb'),
|
2013-03-27 19:13:52 +01:00
|
|
|
notify => Class['nginx::service'],
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
2013-05-20 16:30:32 +02:00
|
|
|
|
2013-04-16 18:12:32 +02:00
|
|
|
#Generate ssl key/cert with provided file-locations
|
2013-05-20 16:30:32 +02:00
|
|
|
|
|
|
|
$cert = regsubst($name,' ','_')
|
|
|
|
|
|
|
|
file { "${nginx::params::nx_conf_dir}/${cert}.crt":
|
2013-04-16 18:12:32 +02:00
|
|
|
ensure => $ensure,
|
|
|
|
mode => '0644',
|
|
|
|
source => $ssl_cert,
|
|
|
|
}
|
2013-05-20 16:30:32 +02:00
|
|
|
file { "${nginx::params::nx_conf_dir}/${cert}.key":
|
2013-04-16 18:12:32 +02:00
|
|
|
ensure => $ensure,
|
|
|
|
mode => '0644',
|
|
|
|
source => $ssl_key,
|
|
|
|
}
|
2011-06-15 21:40:42 +02:00
|
|
|
}
|
|
|
|
}
|