Sample (and simple) NGINX configuration as a load-balancer, using SaltStack's peer communication to retrieve list of backend servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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