diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index f612bb2..ea6e9a6 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -32,6 +32,9 @@ $ensure = present, $vhost = undef, $www_root = undef, + $create_www_root = false, + $owner = '', + $groupowner = '', $redirect = undef, $index_files = ['index.html', 'index.htm', 'index.php'], $proxy = undef, @@ -53,6 +56,18 @@ notify => $nginx::manage_service_autorestart, } + $bool_create_www_root = any2bool($create_www_root) + + $real_owner = $owner ? { + '' => "${nginx::config_file_owner}", + default => $owner, + } + + $real_groupowner = $groupowner ? { + '' => "${nginx::config_file_group}", + default => $groupowner, + } + ## Shared Variables $ensure_real = $ensure ? { 'absent' => absent, @@ -89,6 +104,14 @@ fail('Cannot define both proxy and redirect in a virtual host') } + if $bool_create_www_root == true { + file { $www_root: + ensure => directory, + owner => $real_owner, + group => $real_groupowner, + } + } + ## Create stubs for vHost File Fragment Pattern concat::fragment { "${vhost}+${location}+50.tmp": ensure => $ensure, diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 4a87054..256ae41 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -48,13 +48,18 @@ $proxy_read_timeout = '90', $index_files = ['index.html', 'index.htm', 'index.php'], $template_header = 'nginx/vhost/vhost_header.erb', + $template_fastcgi = 'nginx/vhost/vhost_fastcgi.erb', $template_footer = 'nginx/vhost/vhost_footer.erb', $template_ssl_header = 'nginx/vhost/vhost_ssl_header.erb', $template_ssl_footer = 'nginx/vhost/vhost_footer.erb', $template_ssl_proxy = 'nginx/vhost/vhost_location_proxy.erb', $template_proxy = 'nginx/vhost/vhost_location_proxy.erb', $template_directory = 'nginx/vhost/vhost_location_directory.erb', - $www_root = undef + $www_root = undef, + $create_www_root = false, + $owner = '', + $groupowner = '', + $fastcgi = absent, ) { File { @@ -63,7 +68,21 @@ mode => '0644', require => Package['nginx'] } + + include nginx + include nginx::params include concat::setup + + $real_owner = $owner ? { + '' => "${nginx::process_user}", + default => $owner, + } + + $real_groupowner = $groupowner ? { + '' => "${nginx::process_user}", + default => $groupowner, + } + concat { "${nginx::config_dir}/sites-available/${name}.conf": } @@ -108,12 +127,23 @@ proxy => $proxy, proxy_read_timeout => $proxy_read_timeout, www_root => $www_root, + create_www_root => $create_www_root, + owner => $real_owner, + groupowner => $real_groupowner, notify => $nginx::manage_service_autorestart, template_proxy => $template_proxy, template_ssl_proxy => $template_ssl_proxy, template_directory => $template_directory, } + concat::fragment { "${name}+68-fastcgi.tmp": + order => '68', + content => template("${template_fastcgi}"), + ensure => $fastcgi, + notify => $nginx::manage_service_autorestart, + target => "${nginx::config_dir}/sites-available/${name}.conf", + } + # Create a proper file close stub. concat::fragment { "${name}+69.tmp": order => '69', diff --git a/templates/vhost/vhost_fastcgi.erb b/templates/vhost/vhost_fastcgi.erb new file mode 100644 index 0000000..98b0fa3 --- /dev/null +++ b/templates/vhost/vhost_fastcgi.erb @@ -0,0 +1,12 @@ + + location ~ \.php$ { + try_files $uri =404; + + fastcgi_split_path_info ^(.+\.php)(/.+)$; + + fastcgi_pass unix:/var/run/php5-fpm-<%= @real_owner %>.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_script_name; + include fastcgi_params; + }