You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
ansible-role-nginx/templates/django-vhost.j2

65 lines
1.7 KiB

4 years ago
# {{ ansible_managed }}
upstream {{ item.upstream.name }} {
4 years ago
server {{ item.upstream.server }};
4 years ago
}
server {
4 years ago
listen 80;
{% if item.enable_https %}
listen 443 ssl {% if item.enable_http2 | default(false) %}http2{% endif %};
{% endif %}
server_name {% for server_name in item.server_names %}{{ server_name }} {% endfor %};
4 years ago
4 years ago
access_log /var/log/nginx/{{ item.access_log | default(item.filename) }}.access.log;
error_log /var/log/nginx/{{ item.error_log | default(item.filename) }}.error.log;
4 years ago
4 years ago
{% if item.enable_https | default(true) %}
if ($scheme = http) {
return 301 https://$host$request_uri;
}
{% endif %}
4 years ago
4 years ago
ssl_certificate {{ item.certificate }};
ssl_certificate_key {{ item.private_key }};
ssl_trusted_certificate {{ item.certificate }};
4 years ago
4 years ago
{% if item.error_page is defined %}
4 years ago
4 years ago
error_page {{ item.error_page }};
4 years ago
4 years ago
{% endif %}
4 years ago
4 years ago
{% if item.static_root %}
location /static/ {
alias {{ item.static_root }};
}
{% endif %}
4 years ago
4 years ago
{% if item.media_root %}
location /media/ {
alias {{ item.media_root }};
}
{% endif %}
4 years ago
4 years ago
{% for location in item.additional_locations | default([]) %}
location {{ location.path }} {
alias {{ location.alias }};
}
{% endfor %}
{% for config in item.extra_snippets %}
{% filter indent(4) %}
{% include config.template %}
{% endfilter %}
4 years ago
4 years ago
{% endfor %}
location / {
proxy_pass http://{{ item.upstream.name }};
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}