commit
086510c520
6 changed files with 137 additions and 3 deletions
|
@ -36,6 +36,8 @@
|
|||
# [*fastcgi_script*] - optional SCRIPT_FILE parameter
|
||||
# [*fastcgi_split_path*] - Allows settings of fastcgi_split_path_info so
|
||||
# that you can split the script_name and path_info via regex
|
||||
# [*uwsgi*] - location of uwsgi (host:port)
|
||||
# [*uwsgi_params*] - optional alternative uwsgi_params file to use
|
||||
# [*ssl*] - Indicates whether to setup SSL bindings for
|
||||
# this location.
|
||||
# [*ssl_only*] - Required if the SSL and normal vHost have the
|
||||
|
@ -145,6 +147,8 @@ define nginx::resource::location (
|
|||
$fastcgi_params = "${::nginx::config::conf_dir}/fastcgi_params",
|
||||
$fastcgi_script = undef,
|
||||
$fastcgi_split_path = undef,
|
||||
$uwsgi = undef,
|
||||
$uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params",
|
||||
$ssl = false,
|
||||
$ssl_only = false,
|
||||
$location_alias = undef,
|
||||
|
@ -217,6 +221,10 @@ define nginx::resource::location (
|
|||
if ($fastcgi_split_path != undef) {
|
||||
validate_string($fastcgi_split_path)
|
||||
}
|
||||
if ($uwsgi != undef) {
|
||||
validate_string($uwsgi)
|
||||
}
|
||||
validate_string($uwsgi_params)
|
||||
|
||||
validate_bool($internal)
|
||||
|
||||
|
@ -302,13 +310,14 @@ define nginx::resource::location (
|
|||
if ($vhost == undef) {
|
||||
fail('Cannot create a location reference without attaching to a virtual host')
|
||||
}
|
||||
if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) and ($fastcgi == undef) and ($location_custom_cfg == undef) and ($internal == false)) {
|
||||
fail('Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, stub_status, internal, or location_custom_cfg defined')
|
||||
if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) and ($fastcgi == undef) and ($uwsgi == undef) and ($location_custom_cfg == undef) and ($internal == false)) {
|
||||
fail('Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, uwsgi, stub_status, internal, or location_custom_cfg defined')
|
||||
}
|
||||
if (($www_root != undef) and ($proxy != undef)) {
|
||||
fail('Cannot define both directory and proxy in a virtual host')
|
||||
}
|
||||
|
||||
# Use proxy, fastcgi or uwsgi template if $proxy is defined, otherwise use directory template.
|
||||
# fastcgi_script is deprecated
|
||||
if ($fastcgi_script != undef) {
|
||||
warning('The $fastcgi_script parameter is deprecated; please use $fastcgi_param instead to define custom fastcgi_params!')
|
||||
|
@ -329,6 +338,8 @@ define nginx::resource::location (
|
|||
$content_real = template('nginx/vhost/locations/stub_status.erb')
|
||||
} elsif ($fastcgi != undef) {
|
||||
$content_real = template('nginx/vhost/locations/fastcgi.erb')
|
||||
} elsif ($uwsgi != undef) {
|
||||
$content_real = template('nginx/vhost/locations/uwsgi.erb')
|
||||
} elsif ($www_root != undef) {
|
||||
$content_real = template('nginx/vhost/locations/directory.erb')
|
||||
} else {
|
||||
|
@ -343,6 +354,15 @@ define nginx::resource::location (
|
|||
}
|
||||
}
|
||||
|
||||
if $ensure == present and $uwsgi != undef and !defined(File[$uwsgi_params]) {
|
||||
file { $uwsgi_params:
|
||||
ensure => present,
|
||||
mode => '0770',
|
||||
content => template('nginx/vhost/uwsgi_params.erb'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## Create stubs for vHost File Fragment Pattern
|
||||
if ($ssl_only != true) {
|
||||
$tmpFile=md5("${vhost_sanitized}-${priority}-${location_sanitized}")
|
||||
|
|
|
@ -198,6 +198,8 @@ define nginx::resource::vhost (
|
|||
$fastcgi = undef,
|
||||
$fastcgi_params = "${::nginx::config::conf_dir}/fastcgi_params",
|
||||
$fastcgi_script = undef,
|
||||
$uwsgi = undef,
|
||||
$uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params",
|
||||
$index_files = [
|
||||
'index.html',
|
||||
'index.htm',
|
||||
|
@ -332,6 +334,10 @@ define nginx::resource::vhost (
|
|||
if ($fastcgi_script != undef) {
|
||||
validate_string($fastcgi_script)
|
||||
}
|
||||
if ($uwsgi != undef) {
|
||||
validate_string($uwsgi)
|
||||
}
|
||||
validate_string($uwsgi_params)
|
||||
validate_array($index_files)
|
||||
if ($autoindex != undef) {
|
||||
validate_string($autoindex)
|
||||
|
@ -525,6 +531,8 @@ define nginx::resource::vhost (
|
|||
fastcgi => $fastcgi,
|
||||
fastcgi_params => $fastcgi_params,
|
||||
fastcgi_script => $fastcgi_script,
|
||||
uwsgi => $uwsgi,
|
||||
uwsgi_params => $uwsgi_params,
|
||||
try_files => $try_files,
|
||||
www_root => $www_root,
|
||||
autoindex => $autoindex,
|
||||
|
@ -569,6 +577,14 @@ define nginx::resource::vhost (
|
|||
}
|
||||
}
|
||||
|
||||
if $uwsgi != undef and !defined(File[$uwsgi_params]) {
|
||||
file { $uwsgi_params:
|
||||
ensure => present,
|
||||
mode => '0770',
|
||||
content => template('nginx/vhost/uwsgi_params.erb'),
|
||||
}
|
||||
}
|
||||
|
||||
if ($listen_port != $ssl_port) {
|
||||
concat::fragment { "${name_sanitized}-header":
|
||||
target => $config_file,
|
||||
|
|
|
@ -519,6 +519,65 @@ describe 'nginx::resource::location' do
|
|||
end
|
||||
end
|
||||
|
||||
describe "vhost_location_uwsgi template content" do
|
||||
let :default_params do
|
||||
{
|
||||
:location => 'location',
|
||||
:uwsgi => 'unix:/home/project/uwsgi.socket',
|
||||
:vhost => 'vhost1'
|
||||
}
|
||||
end
|
||||
|
||||
[
|
||||
{
|
||||
:title => 'should set www_root',
|
||||
:attr => 'www_root',
|
||||
:value => '/',
|
||||
:match => %r'\s+root\s+/;'
|
||||
},
|
||||
{
|
||||
:title => 'should set try_file(s)',
|
||||
:attr => 'try_files',
|
||||
:value => ['name1','name2'],
|
||||
:match => %r'\s+try_files\s+name1 name2;',
|
||||
},
|
||||
{
|
||||
:title => 'should set uwsgi_params',
|
||||
:attr => 'uwsgi_params',
|
||||
:value => 'value',
|
||||
:match => %r'\s+include\s+value;'
|
||||
},
|
||||
{
|
||||
:title => 'should set uwsgi_pass',
|
||||
:attr => 'uwsgi',
|
||||
:value => 'value',
|
||||
:match => %r'\s+uwsgi_pass\s+value;'
|
||||
},
|
||||
].each do |param|
|
||||
context "when #{param[:attr]} is #{param[:value]}" do
|
||||
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
|
||||
|
||||
it { is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")) }
|
||||
it param[:title] do
|
||||
fragment = Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")
|
||||
matches = Array(param[:match])
|
||||
|
||||
if matches.all? { |m| m.is_a? Regexp }
|
||||
matches.each { |item| is_expected.to contain_concat__fragment(fragment).with_content(item) }
|
||||
else
|
||||
lines = catalogue.resource('concat::fragment', fragment).send(:parameters)[:content].split("\n")
|
||||
expect(lines & matches).to eq(matches)
|
||||
end
|
||||
|
||||
Array(param[:notmatch]).each do |item|
|
||||
is_expected.to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).without_content(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "vhost_location_proxy template content" do
|
||||
[
|
||||
{
|
||||
|
@ -642,6 +701,13 @@ describe 'nginx::resource::location' do
|
|||
it { is_expected.to contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
|
||||
end
|
||||
|
||||
context 'when uwsgi => "unix:/home/project/uwsgi.socket"' do
|
||||
let :params do { :uwsgi => 'uwsgi_upstream', :vhost => 'vhost1' } end
|
||||
|
||||
it { should contain_file('/etc/nginx/uwsgi_params') }
|
||||
end
|
||||
|
||||
|
||||
context 'when ssl_only => true' do
|
||||
let :params do { :ssl_only => true, :vhost => 'vhost1', :www_root => '/', } end
|
||||
it { is_expected.not_to contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-rspec-test")) }
|
||||
|
@ -678,7 +744,7 @@ describe 'nginx::resource::location' do
|
|||
:vhost => 'vhost1',
|
||||
} end
|
||||
|
||||
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, stub_status, internal, or location_custom_cfg defined/) }
|
||||
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, uwsgi, stub_status, internal, or location_custom_cfg defined/) }
|
||||
end
|
||||
|
||||
context "www_root and proxy are set" do
|
||||
|
|
|
@ -763,6 +763,15 @@ describe 'nginx::resource::vhost' do
|
|||
it { is_expected.to contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
|
||||
end
|
||||
|
||||
context 'when uwsgi => "uwsgi_upstream"' do
|
||||
let :params do default_params.merge({
|
||||
:uwsgi => 'uwsgi_upstream',
|
||||
}) end
|
||||
|
||||
it { should contain_file('/etc/nginx/uwsgi_params').with_mode('0770') }
|
||||
end
|
||||
|
||||
|
||||
context 'when listen_port == ssl_port' do
|
||||
let :params do default_params.merge({
|
||||
:listen_port => 80,
|
||||
|
|
8
templates/vhost/locations/uwsgi.erb
Normal file
8
templates/vhost/locations/uwsgi.erb
Normal file
|
@ -0,0 +1,8 @@
|
|||
<% if defined? @www_root -%>
|
||||
root <%= @www_root %>;
|
||||
<% end -%>
|
||||
<% if @try_files -%>
|
||||
try_files<% @try_files.each do |try| -%> <%= try %><% end -%>;
|
||||
<% end -%>
|
||||
include <%= @uwsgi_params %>;
|
||||
uwsgi_pass <%= @uwsgi %>;
|
15
templates/vhost/uwsgi_params.erb
Normal file
15
templates/vhost/uwsgi_params.erb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# This file managed by puppet on host <%= @fqdn %>
|
||||
|
||||
uwsgi_param QUERY_STRING $query_string;
|
||||
uwsgi_param REQUEST_METHOD $request_method;
|
||||
uwsgi_param CONTENT_TYPE $content_type;
|
||||
uwsgi_param CONTENT_LENGTH $content_length;
|
||||
uwsgi_param REQUEST_URI $request_uri;
|
||||
uwsgi_param PATH_INFO $document_uri;
|
||||
uwsgi_param DOCUMENT_ROOT $document_root;
|
||||
uwsgi_param SERVER_PROTOCOL $server_protocol;
|
||||
uwsgi_param REMOTE_ADDR $remote_addr;
|
||||
uwsgi_param REMOTE_PORT $remote_port;
|
||||
uwsgi_param SERVER_ADDR $server_addr;
|
||||
uwsgi_param SERVER_PORT $server_port;
|
||||
uwsgi_param SERVER_NAME $server_name;
|
Loading…
Reference in a new issue