Skip to content

Instantly share code, notes, and snippets.

@tomeduarte

tomeduarte/gist:6340205

Last active Dec 21, 2015
Embed
What would you like to do?
Sample (and simple) NGINX configuration as a load-balancer, using SaltStack's peer communication to retrieve list of backend servers.
# /srv/salt/shared/nginx/files/sites-available/default.lb
upstream app_nodes {
# Build list of backend servers
# using peer communication as the mine is cached and slow to pick up new hosts
{% for server,ips in
salt['publish.publish'](
'G@roles:appnode',
'network.ip_addrs', expr_form='compound').items() -%}
# host: {{ server }}
{% for ip in ips -%}
server {{ ip }}:80 ;
{% endfor -%}
{% endfor -%}
}
server {
listen 80 default_server;
server_name {{ realm }}.example.com www.{{ realm }}.example.com;
error_log /var/log/nginx/default/error.log;
location / {
proxy_pass http://app_nodes;
}
}
# /srv/salt/shared/nginx/init.sls
/etc/nginx/sites-available/default:
file.managed:
- source: salt://shared/nginx/files/sites-available/default.lb
- template: jinja
- require:
- pkg: shared.nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment