Skip to content

Commit

Permalink
Added support for multiple "applications" in different hostnames thro…
Browse files Browse the repository at this point in the history
…ugh the use of fastcgi environment variables set via nginx conf
  • Loading branch information
josegonzalez committed Aug 6, 2011
1 parent 91cad69 commit f1bc19a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
55 changes: 38 additions & 17 deletions sites/recipes/nginx_cakephp.rb
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions sites/templates/default/nginx_php.erb
Expand Up @@ -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 {
Expand Down

0 comments on commit f1bc19a

Please sign in to comment.