Merge pull request #72 from 0x28d/master
Allow to generate custom locations in load_balancer mode
This commit is contained in:
commit
39dd5a29cc
79
README.md
79
README.md
@ -331,10 +331,16 @@ nginx_http_template:
|
||||
cert: ssl/default.crt
|
||||
key: ssl/default.key
|
||||
web_server:
|
||||
locations:
|
||||
default:
|
||||
location: /
|
||||
html_file_location: /usr/share/nginx/html
|
||||
html_file_name: index.html
|
||||
http_demo_conf: false
|
||||
load_balancer:
|
||||
locations:
|
||||
location1:
|
||||
location: /
|
||||
proxy_pass: backend
|
||||
health_check_plus: false
|
||||
upstreams:
|
||||
@ -384,6 +390,79 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a
|
||||
- role: nginxinc.nginx
|
||||
```
|
||||
|
||||
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing the open source version of NGINX as a simple web server.
|
||||
|
||||
```yaml
|
||||
---
|
||||
- hosts: localhost
|
||||
become: true
|
||||
roles:
|
||||
- ansible-role-nginx
|
||||
vars:
|
||||
nginx_http_template_enable: true
|
||||
nginx_http_template:
|
||||
default:
|
||||
template_file: http/default.conf.j2
|
||||
conf_file_name: default.conf
|
||||
conf_file_location: /etc/nginx/conf.d/
|
||||
port: 80
|
||||
server_name: localhost
|
||||
error_page: /usr/share/nginx/html
|
||||
web_server:
|
||||
locations:
|
||||
default:
|
||||
location: /
|
||||
html_file_location: /usr/share/nginx/html
|
||||
html_file_name: index.html
|
||||
```
|
||||
|
||||
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing the open source version of NGINX as a reverse proxy.
|
||||
|
||||
```yaml
|
||||
---
|
||||
- hosts: localhost
|
||||
become: true
|
||||
roles:
|
||||
- nginxinc.nginx
|
||||
vars:
|
||||
nginx_http_template_enable: true
|
||||
nginx_http_template:
|
||||
load_balancer:
|
||||
locations:
|
||||
frontend:
|
||||
location: /
|
||||
proxy_pass: frontend_servers
|
||||
backend:
|
||||
location: /backend
|
||||
proxy_pass: backend_servers
|
||||
upstreams:
|
||||
upstream_1:
|
||||
name: frontend_servers
|
||||
lb_method: least_conn
|
||||
zone_name: frontend
|
||||
zone_size: 64k
|
||||
sticky_cookie: false
|
||||
servers:
|
||||
frontend_server_1:
|
||||
address: localhost
|
||||
port: 80
|
||||
weight: 1
|
||||
health_check: max_fails=3 fail_timeout=5s
|
||||
upstream_2:
|
||||
name: backend_servers
|
||||
lb_method: least_conn
|
||||
zone_name: backend
|
||||
zone_size: 64k
|
||||
sticky_cookie: false
|
||||
servers:
|
||||
backend_server_1:
|
||||
address: localhost
|
||||
port: 8080
|
||||
weight: 1
|
||||
health_check: max_fails=3 fail_timeout=5s
|
||||
```
|
||||
|
||||
|
||||
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing NGINX Plus.
|
||||
|
||||
```yaml
|
||||
|
@ -164,10 +164,16 @@ nginx_http_template:
|
||||
cert: ssl/default.crt
|
||||
key: ssl/default.key
|
||||
web_server:
|
||||
locations:
|
||||
default:
|
||||
location: /
|
||||
html_file_location: /usr/share/nginx/html
|
||||
html_file_name: index.html
|
||||
http_demo_conf: false
|
||||
load_balancer:
|
||||
locations:
|
||||
backend:
|
||||
location: /
|
||||
proxy_pass: backend
|
||||
health_check_plus: false
|
||||
upstreams:
|
||||
|
@ -24,8 +24,9 @@ server {
|
||||
{% endif %}
|
||||
server_name {{ item.value.server_name }};
|
||||
{% if item.value.load_balancer is defined %}
|
||||
location / {
|
||||
proxy_pass http://{{ item.value.load_balancer.proxy_pass }};
|
||||
{% for location in item.value.load_balancer.locations %}
|
||||
location {{ item.value.load_balancer.locations[location].location }} {
|
||||
proxy_pass http://{{ item.value.load_balancer.locations[location].proxy_pass }};
|
||||
{% if item.value.load_balancer.health_check_plus %}
|
||||
health_check;
|
||||
{% endif %}
|
||||
@ -34,12 +35,16 @@ server {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if item.value.web_server is defined %}
|
||||
location / {
|
||||
root {{ item.value.web_server.html_file_location }};
|
||||
index {{ item.value.web_server.html_file_name }};
|
||||
{% for location in item.value.web_server.locations %}
|
||||
location {{ item.value.web_server.locations[location].location }} {
|
||||
root {{ item.value.web_server.locations[location].html_file_location }};
|
||||
index {{ item.value.web_server.locations[location].html_file_name }};
|
||||
}
|
||||
{% endfor %}
|
||||
{% if item.value.web_server.http_demo_conf %}
|
||||
sub_filter_once off;
|
||||
sub_filter 'server_hostname' '$hostname';
|
||||
|
@ -15,6 +15,9 @@
|
||||
server_name: localhost
|
||||
error_page: /usr/share/nginx/html
|
||||
web_server:
|
||||
locations:
|
||||
default:
|
||||
location: /
|
||||
html_file_location: /usr/share/nginx/html
|
||||
html_file_name: index.html
|
||||
http_demo_conf: false
|
||||
|
Loading…
Reference in New Issue
Block a user