It makes it possible to serve multiple Discord instances to different hosts from a single nginx load balancer Right now we run one for Kosmos and one for remoteStorage
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
#
 | 
						|
# Cookbook:: discourse
 | 
						|
# Recipe:: nginx
 | 
						|
#
 | 
						|
 | 
						|
include_recipe "kosmos-nginx"
 | 
						|
 | 
						|
domain = node['discourse']['domain']
 | 
						|
discourse_role = node['discourse']['role']
 | 
						|
 | 
						|
upstream_ip_addresses = []
 | 
						|
search(:node, "role:#{discourse_role}").each do |n|
 | 
						|
  upstream_ip_addresses << n["knife_zero"]["host"]
 | 
						|
end
 | 
						|
# No Discourse host, stop here
 | 
						|
if upstream_ip_addresses.empty?
 | 
						|
  Chef::Log.warn("No server with '#{discourse_role}' role. Stopping here.")
 | 
						|
  return
 | 
						|
end
 | 
						|
 | 
						|
nginx_certbot_site domain
 | 
						|
 | 
						|
template "#{node['nginx']['dir']}/sites-available/#{domain}" do
 | 
						|
  source "nginx_conf.erb"
 | 
						|
  owner 'www-data'
 | 
						|
  mode 0640
 | 
						|
  variables server_name:           domain,
 | 
						|
            ssl_cert:              "/etc/letsencrypt/live/#{domain}/fullchain.pem",
 | 
						|
            ssl_key:               "/etc/letsencrypt/live/#{domain}/privkey.pem",
 | 
						|
            upstream_port:         node['discourse']['port'],
 | 
						|
            upstream_name:         discourse_role,
 | 
						|
            upstream_ip_addresses: upstream_ip_addresses
 | 
						|
 | 
						|
  notifies :reload, 'service[nginx]', :delayed
 | 
						|
end
 | 
						|
 | 
						|
nginx_site domain do
 | 
						|
  action :enable
 | 
						|
end
 |