Skip to content

Commit

Permalink
Configure nginx load balancer with all nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
malvads committed Jun 10, 2024
1 parent f8ca08a commit a794aac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@
action :add_webui_conf_nginx do
begin
webui_port = new_resource.port
webui_hosts = new_resource.hosts
routes = local_routes()
cdomain = new_resource.cdomain

Expand All @@ -514,7 +515,7 @@
group "nginx"
mode 0644
cookbook "webui"
variables(:webui_port => webui_port, :cdomain => cdomain)
variables(:webui_hosts => webui_hosts, :webui_port => webui_port, :cdomain => cdomain)
notifies :restart, "service[nginx]"
end

Expand Down
1 change: 1 addition & 0 deletions resources/resources/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
attribute :user, :kind_of => String, :default => "webui"
attribute :group, :kind_of => String, :default => "webui"
attribute :port, :kind_of => Integer, :default => 8001
attribute :hosts, :kind_of => Array, :default => ["localhost"]
attribute :hostname, :kind_of => String
attribute :cdomain, :kind_of => String, :default => "redborder.cluster"
attribute :web_dir, :kind_of => String, :default => "/var/www/rb-rails"
Expand Down
4 changes: 3 additions & 1 deletion resources/templates/default/webui.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#######################################################

upstream webui {
server localhost:<%= @webui_port %> weight=2 max_fails=3 fail_timeout=5s;
<% @webui_hosts.each do |server| %>
server <%= server %>:<%= @webui_port %> max_fails=3 fail_timeout=120;
<% end %>
}

server {
Expand Down

0 comments on commit a794aac

Please sign in to comment.