Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration of custom fastcgi_params [fixes #389] #396

Merged
merged 5 commits into from
Aug 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ define web::nginx_ssl_with_redirect (
}
```

## Add custom fastcgi_params

```puppet
nginx::resource::location { "some_root":
ensure => present,
location => '/some/url',
fastcgi => "127.0.0.1:9000",
fastcgi_param => {
'APP_ENV' => 'local',
},
}
```

# Call class web::nginx_ssl_with_redirect

```puppet
Expand Down
21 changes: 21 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# value of 90 seconds
# [*proxy_set_header*] - Array of vhost headers to set
# [*fastcgi*] - location of fastcgi (host:port)
# [*fastcgi_param*] - Set additional custom fastcgi_params
# [*fastcgi_params*] - optional alternative fastcgi_params file to use
# [*fastcgi_script*] - optional SCRIPT_FILE parameter
# [*fastcgi_split_path*] - Allows settings of fastcgi_split_path_info so
Expand Down Expand Up @@ -107,6 +108,17 @@
# vhost => 'test2.local',
# location_cfg_append => $my_config,
# }
#
# Add Custom fastcgi_params
# nginx::resource::location { 'test2.local-bob':
# ensure => present,
# www_root => '/var/www/bob',
# location => '/bob',
# vhost => 'test2.local',
# fastcgi_param => {
# 'APP_ENV' => 'local',
# }
# }

define nginx::resource::location (
$ensure = present,
Expand All @@ -125,6 +137,7 @@
$proxy_connect_timeout = $nginx::config::proxy_connect_timeout,
$proxy_set_header = $nginx::config::proxy_set_header,
$fastcgi = undef,
$fastcgi_param = undef,
$fastcgi_params = "${nginx::config::conf_dir}/fastcgi_params",
$fastcgi_script = undef,
$fastcgi_split_path = undef,
Expand Down Expand Up @@ -186,6 +199,9 @@
if ($fastcgi != undef) {
validate_string($fastcgi)
}
if ($fastcgi_param != undef) {
validate_hash($fastcgi_param)
}
validate_string($fastcgi_params)
if ($fastcgi_script != undef) {
validate_string($fastcgi_script)
Expand Down Expand Up @@ -287,6 +303,11 @@
if (($www_root != undef) and ($proxy != undef)) {
fail('Cannot define both directory and proxy in a virtual host')
}

# 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!')
}

# Use proxy or fastcgi template if $proxy is defined, otherwise use directory template.
if ($proxy != undef) {
Expand Down
26 changes: 26 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,32 @@
without_content(/^[ ]+fastcgi_param\s+SCRIPT_FILENAME\s+.+?;/)
end
end

context "when fastcgi_param is {'CUSTOM_PARAM' => 'value'}" do
let :params do default_params.merge({ :fastcgi_param => {'CUSTOM_PARAM' => 'value', 'CUSTOM_PARAM2' => 'value2'} }) end
it "should set fastcgi_param" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
with_content(%r|fastcgi_param\s+CUSTOM_PARAM\s+value;|).
with_content(%r|fastcgi_param\s+CUSTOM_PARAM2\s+value2;|)
end
it "should add comment # Enable custom fastcgi_params" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
with_content(%r|# Enable custom fastcgi_params\s+|)
end
end

context "when fastcgi_param is not set" do
let :params do default_params end
it "should not set fastcgi_param" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
without_content(/fastcgi_param\s+CUSTOM_PARAM\s+.+?;/).
without_content(/fastcgi_param\s+CUSTOM_PARAM2\s+.+?;/)
end
it "should not add comment # Enable custom fastcgi_params" do
should contain_concat__fragment(Digest::MD5.hexdigest("vhost1-500-#{params[:location]}")).
without_content(/# Enable custom fastcgi_params\s+/)
end
end
end

describe "vhost_location_proxy template content" do
Expand Down
18 changes: 9 additions & 9 deletions templates/vhost/fastcgi_params.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# This file managed by puppet on host <%= @fqdn %>

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
Expand All @@ -21,7 +21,7 @@ fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

fastcgi_param HTTPS $https;
fastcgi_param HTTPS $https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
6 changes: 6 additions & 0 deletions templates/vhost/locations/fastcgi.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
<% if defined? @fastcgi_script %>
fastcgi_param SCRIPT_FILENAME <%= @fastcgi_script %>;
<% end -%>
<% if defined? @fastcgi_param %>
# Enable custom fastcgi_params
<% fastcgi_param.each_pair do |key, val| -%>
fastcgi_param <%= key %> <%= val %>;
<% end -%>
<% end %>
12 changes: 12 additions & 0 deletions tests/location_params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include nginx

nginx::resource::location { 'www.test.com-params':
ensure => present,
location => '/some/url',
vhost => 'www.test.com',
fastcgi_param => {
'APP_ENV' => 'production',
'APP_VERSION' => '0.1.10',
'APP_SECRET' => 'hisfaihicasagfkjsa',
},
}