From e05c59f5470477ff10952094e930f70140005f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20C=C3=B4t=C3=A9-Tremblay?= Date: Thu, 23 Feb 2017 14:58:41 -0500 Subject: [PATCH] Implements uwsgi_pass + static assets support --- defaults/main.yml | 11 +++++++++++ tasks/main.yml | 3 +++ tasks/uwsgi_pass.yml | 14 ++++++++++++++ templates/simple_uwsgi_pass.conf | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tasks/uwsgi_pass.yml create mode 100644 templates/simple_uwsgi_pass.conf diff --git a/defaults/main.yml b/defaults/main.yml index 2d894c5..a06cbda 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,6 +15,17 @@ _nginx_simple_proxy_passes_item: extra_conf: "" ssl_only: no +# A list of uwsgi_pass items to configure. A list of hashes following the structure of +# _nginx_simple_uwsgi_passes_item +nginx_simple_uwsgi_passes: [] +_nginx_simple_uwsgi_passes_item: + server_name: '_' + socket_path: '' + extra_conf: '' + static_root: '' + static_paths: [] + ssl_only: no + # Whether we generate a collection of useful snippets in /etc/nginx/snippets. # See README. nginx_generate_snippets: yes diff --git a/tasks/main.yml b/tasks/main.yml index 311bb12..244d4ca 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,5 +11,8 @@ - include: proxy_pass.yml with_items: "{{ nginx_simple_proxy_passes }}" +- include: uwsgi_pass.yml + with_items: "{{ nginx_simple_uwsgi_passes }}" + - include: catchall.yml when: nginx_catchall_enable diff --git a/tasks/uwsgi_pass.yml b/tasks/uwsgi_pass.yml new file mode 100644 index 0000000..3e48252 --- /dev/null +++ b/tasks/uwsgi_pass.yml @@ -0,0 +1,14 @@ +- set_fact: + uwsgi_pass: "{{ item }}" + +- set_fact: + conf_filename: "{% if uwsgi_pass.server_name == '_' %}catchall_simple_uwsgi_pass{% else %}{{ uwsgi_pass.server_name }}{% endif %}" +- name: Check if SSL config is there + stat: path="/etc/nginx/snippets/{{ conf_filename }}.ssl.conf" + register: ssl_config_file + +- name: Create nginx sites config + template: src=simple_uwsgi_pass.conf dest=/etc/nginx/sites-enabled/{{ conf_filename }}.conf + notify: + - nginx restart + diff --git a/templates/simple_uwsgi_pass.conf b/templates/simple_uwsgi_pass.conf new file mode 100644 index 0000000..b6151ac --- /dev/null +++ b/templates/simple_uwsgi_pass.conf @@ -0,0 +1,32 @@ +server { + {% if not uwsgi_pass.ssl_only|default(False) -%} + listen 80; + {%- endif %} + listen 443 ssl; + server_name {{ uwsgi_pass.server_name }}; + + {% if ssl_config_file.stat.exists -%} + include {{ ssl_config_file.stat.path }}; + {%- else %} + include snippets/snakeoil.conf; + {%- endif %} + + {% if acme_well_known_config_file.stat.exists -%} + include snippets/acme_well_known.conf; + {%- endif %} + + {% for path in uwsgi_pass.static_paths %} + location {{ path }} { + alias {{ uwsgi_pass.static_root }}{{ path }}; + } + {% endfor %} + + error_log /var/log/nginx/{{ uwsgi_pass.server_name }}_error.log; + access_log /var/log/nginx/{{ uwsgi_pass.server_name }}_access.log; + + location / { + uwsgi_pass unix:{{ uwsgi_pass.socket_path }}; + include uwsgi_params; + {{ uwsgi_pass.extra_conf|default('') }} + } +}