Browse Source

use nginx include directive to enable support for multiple location from different role on the same domain

python3
Andrea Cimbalo 7 years ago
parent
commit
e1a4794ec7
4 changed files with 31 additions and 10 deletions
  1. +1
    -0
      roles/nginx/defaults/main.yml
  2. +28
    -3
      roles/nginx/tasks/main.yaml
  3. +1
    -6
      roles/nginx/templates/base.j2
  4. +1
    -1
      roles/nginx/templates/proxy.conf.nginx.j2

+ 1
- 0
roles/nginx/defaults/main.yml View File

@ -5,3 +5,4 @@
# max body size in Mb
max_body_size: 8
server_fqdn: "{{ ansible_hostname }}.lilik.it"
proxy_location_path: ''

+ 28
- 3
roles/nginx/tasks/main.yaml View File

@ -34,10 +34,19 @@
notify:
- restart nginx
- name: create nginx location configuration directory
file:
path: '/etc/nginx/locations/{{ server_fqdn }}/'
state: directory
mode: 0755
owner: www-data
group: www-data
recurse: yes
- name: upload nginx configuration
template:
src: base.j2
dest: "/etc/nginx/sites-available/{{ config_name or 'proxy' }}.conf"
dest: "/etc/nginx/sites-available/{{ server_fqdn }}.conf"
notify:
- restart nginx
@ -62,8 +71,24 @@
- name: enable nginx configurations
file:
src: "/etc/nginx/sites-available/{{ config_name or 'proxy' }}.conf"
dest: "/etc/nginx/sites-enabled/{{ config_name or 'proxy' }}.conf"
src: "/etc/nginx/sites-available/{{ server_fqdn }}.conf"
dest: "/etc/nginx/sites-enabled/{{ server_fqdn }}.conf"
state: link
# with_items: "{{ config_names }}"
notify: restart nginx
- name: upload nginx location configuration from parent role
template:
src: "roles/{{ parent_role_path }}/templates/{{ config_name }}.conf.nginx.j2"
dest: "/etc/nginx/locations/{{ server_fqdn }}/{{ config_name }}.conf"
notify:
- restart nginx
when: 'config_name is not none'
- name: upload nginx location configuration for proxy
template:
src: proxy.conf.nginx.j2
dest: "/etc/nginx/locations/{{ server_fqdn }}/{{ parent_role_path or 'proxy' }}.conf"
notify:
- restart nginx
when: 'is_proxy'

+ 1
- 6
roles/nginx/templates/base.j2 View File

@ -28,11 +28,6 @@ server {
## verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /etc/letsencrypt/live/{{ server_fqdn }}/chain.pem;
{% if config_name is not none %}
{% include "roles/%s/templates/%s.conf.nginx.j2" % (parent_role_path, config_name) %}
{% endif %}
{% if is_proxy %}
{% include "proxy.conf.nginx.j2" %}
{% endif %}
include /etc/nginx/locations/{{ server_fqdn }}/*.conf;
}

+ 1
- 1
roles/nginx/templates/proxy.conf.nginx.j2 View File

@ -1,4 +1,4 @@
location / {
location /{{ proxy_location_path }} {
client_max_body_size {{ max_body_size }}M;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";


Loading…
Cancel
Save