Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements uwsgi_pass + static assets support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions tasks/uwsgi_pass.yml
Original file line number Diff line number Diff line change
@@ -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

32 changes: 32 additions & 0 deletions templates/simple_uwsgi_pass.conf
Original file line number Diff line number Diff line change
@@ -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('') }}
}
}