From f1bc19aff94d22b913747b6ac8b93907b97d8afe Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 6 Aug 2011 00:36:35 -0400 Subject: [PATCH] Added support for multiple "applications" in different hostnames through the use of fastcgi environment variables set via nginx conf --- sites/recipes/nginx_cakephp.rb | 55 ++++++++++++++++++--------- sites/templates/default/nginx_php.erb | 5 ++- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/sites/recipes/nginx_cakephp.rb b/sites/recipes/nginx_cakephp.rb index f7515c8..2123e31 100644 --- a/sites/recipes/nginx_cakephp.rb +++ b/sites/recipes/nginx_cakephp.rb @@ -162,24 +162,45 @@ end # Nginx setup - template "#{node[:nginx][:dir]}/sites-available/#{hostname}.#{site_base}-#{environment}" do - source "nginx_php.erb" - owner "root" - group "root" - mode 0644 - variables( - :folder_base=> "#{env_config[:dir]}/#{hostname}/#{site_base}", - :root => "#{env_config[:dir]}/#{hostname}/#{site_base}/public/webroot", - :nick => "#{site_base}.#{hostname}", - :resources => [ "php", "html", "htm" ], - :hostname => hostname, - :subdomain => site_info[:subdomain], - :environment=> environment - ) - end + # Note that each site can have multiple environments (which we are already looping through) + # as well as multiple "apps" pointing at the same environment + # for example, the api and the main app might be the same application, but simply be different + # in their bootstrap and routes folder, based on environment variables + if !site_info[:variables][environment].key?(:apps) + site_info[:variables][environment][:apps] = { + "default" => {"CAKEPHP_APP" => "default"} + } + end + + site_info[:variables][environment][:apps].each do |app_env, env_vars| + template_name = "#{hostname}.#{site_base}-#{environment}" + template_name += "_#{app_env}" unless app_env == "default" + + subdomain = site_info[:subdomain].empty? ? "" : site_info[:subdomain] + "." + subdomain = app_env == "default" ? subdomain : subdomain + app_env + "." + + template "#{node[:nginx][:dir]}/sites-available/#{template_name}" do + source "nginx_php.erb" + owner "root" + group "root" + mode 0644 + variables( + :folder_base=> "#{env_config[:dir]}/#{hostname}/#{site_base}", + :root => "#{env_config[:dir]}/#{hostname}/#{site_base}/public/webroot", + :nick => "#{site_base}.#{hostname}", + :resources => [ "php", "html", "htm" ], + :hostname => hostname, + :subdomain => subdomain, + :environment=> environment, + :app_env => app_env, + :env_vars => env_vars + ) + end + + nginx_site "#{template_name}" do + action :enable + end - nginx_site "#{hostname}.#{site_base}-#{environment}" do - action :enable end end diff --git a/sites/templates/default/nginx_php.erb b/sites/templates/default/nginx_php.erb index 094df24..0fd5681 100644 --- a/sites/templates/default/nginx_php.erb +++ b/sites/templates/default/nginx_php.erb @@ -55,8 +55,9 @@ server { fastcgi_param SCRIPT_FILENAME $document_root$script; fastcgi_param SCRIPT_NAME $script; fastcgi_param PATH_INFO $path_info; - fastcgi_param SYMFONY_APP customer; - fastcgi_param SYMFONY_ENV prod; +<% @env_vars.each do |key, value| -%> + fastcgi_param <%= key %> <%= value %>; +<% end -%> } location ~ /\.ht {