Creates and deploys simple nginx reverse proxy configurations from supplied variables, optionally making use of the load balancing features as well.
At the time, this role does not expose all possible configurations of nginx's load balancing and proxying, but aims to use rational defaults with some configurability.
nginx with reverse proxy support installed on the server to be managed.
nginx_reverse_proxy_proxies
: list of reverse proxy configurations; each configuration needs the following variablesnginx_reverse_proxy_backend_name:
string, name nginx config uses to refer to the backendnginx_reverse_proxy_domains
: list of public-facing domains to be proxiednginx_reverse_proxy_backends
: list of backend servers, including ports and other valid parameters forserver
in theupstream
context of an nginx config filenginx_reverse_proxy_config_name
: name to use for the proxy file (do not include the '.conf' extension, role will add this)
Along with the variables that must be configured for each reverse proxy configuration, some configuration options are available on a per-proxy basis:
balancer_config
: specify a load balancing strategy other than the default round robin. Valid options includeleast_conn
(for least connections) andip_hash
(for session persistence using IP hashing).
See the app2proxy definition in the example playbook below.
nginx_reverse_proxy_config_directory:
location to store config files for nginx (default: /etc/nginx/conf.d
)
nginx_reverse_proxy_nginx_service
: name the nginx service runs under, for the handler restart if config files are changed (default: nginx
)
nginx is expected to be installed on the server being managed
---
- hosts: nginx
remote_user: vagrant
become: yes
vars:
- nginx_reverse_proxy_proxies:
- config_name: app1proxy
backend_name: my-backend-1
backends:
- localhost:1880 weight=2
- localhost:1881
domains:
- app1.192.168.88.10.xip.io
- config_name: app2proxy
backend_name: my-backend-2
backends:
- localhost:1882
- localhost:1883
domains:
- app2.192.168.88.10.xip.io
balancer_config: least_conn;
- config_name: sessionappproxy
backend_name: session-app-backend
backends:
- localhost:1880
- localhost:1881
- localhost:1882
- localhost:1883
domains:
- sessioned-app.192.168.88.10.xip.io
balancer_config: ip_hash;
roles:
- ansible-nginx-reverse-proxy
BSD