I'm using nginx_vhost recipe to apply it to two different roles, let's say frontend
and web
. nginx_vhost recipe has following code on its template for vhost.conf
file:
<% if @upstream %>
upstream <%= @name %> {
<% @servers.each do |server| -%>
server <%= server %> fail_timeout=0;
<% end -%>
<% @sockets.each do |socket| -%>
server <%= socket %> fail_timeout=0;
<% end -%>
}
<% end %>
The code above will write:
upstream app_myproject.com {
server unix:/www/myproject.com/control/shared/sockets/unicorn.sock fail_timeout=0;
}
The problem is: I just need this on frontend
role but not in web
role. I was thinking to include it in the override_attributes section of frontend
role but I'm not sure if that's the best way to do it.
Notice that it provides a new resource named nginx_vhost
from nginx_vhost cookbook, it's supposed to be used into your custom recipes like this:
# foo::frontend
nginx_vhost "app_myproject.com" do
sockets [ "unix:/www/myproject.com/control/shared/sockets/unicorn.sock" ]
end
You can define another resource for the recipe used in your role web:
# foo:web
nginx_vhost "web.myproject.com" do
port 80
stream false # results no stream section in vhost config
end