2015-07-30 18:02:21 +07:00
|
|
|
{% set __listen = item.listen | default(['80']) %}
|
|
|
|
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
2015-07-31 05:38:16 +07:00
|
|
|
{% set __location = item.location | default({}) %}
|
2015-07-30 18:02:21 +07:00
|
|
|
#
|
|
|
|
# {{ ansible_managed }}
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# HTTP
|
|
|
|
#
|
|
|
|
server {
|
|
|
|
{% for port in __listen %}
|
|
|
|
listen {{ port }};
|
|
|
|
{% endfor %}
|
|
|
|
server_name {{ item.name | join(' ') }};
|
|
|
|
{% if item.root is defined %}
|
|
|
|
root {{ item.root }};
|
|
|
|
{% else %}
|
|
|
|
root {{ nginx_root }}/{{ item.name[0] }}/public;
|
|
|
|
{% endif %}
|
|
|
|
{% block template_index %}
|
|
|
|
index {{ item.index | default('index.html index.htm') }};
|
|
|
|
{% endblock %}
|
|
|
|
|
2015-08-28 14:54:43 +07:00
|
|
|
location / {
|
2015-07-30 18:02:21 +07:00
|
|
|
{% block template_try_files %}
|
2015-08-28 14:54:43 +07:00
|
|
|
try_files $uri $uri/ =404;
|
2015-07-30 18:02:21 +07:00
|
|
|
{% endblock %}
|
2015-08-28 14:54:43 +07:00
|
|
|
}
|
2015-07-30 18:02:21 +07:00
|
|
|
|
2015-07-30 20:37:25 +07:00
|
|
|
{% block template_upstream_location %}
|
|
|
|
{% endblock %}
|
2015-07-30 18:02:21 +07:00
|
|
|
{% block template_custom_location %}
|
|
|
|
{% endblock %}
|
|
|
|
|
2015-07-31 05:38:16 +07:00
|
|
|
location ~ /\.ht {
|
2015-07-30 18:02:21 +07:00
|
|
|
deny all;
|
|
|
|
}
|
2015-07-30 20:37:25 +07:00
|
|
|
|
|
|
|
location = /favicon.ico {
|
|
|
|
expires 30d;
|
|
|
|
access_log off;
|
|
|
|
log_not_found off;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ {
|
2015-07-30 18:02:21 +07:00
|
|
|
expires 30d;
|
|
|
|
log_not_found off;
|
|
|
|
}
|
|
|
|
|
2015-07-31 05:38:16 +07:00
|
|
|
{% if __location is iterable and __location | length > 0 %}
|
|
|
|
# --> Custom locations
|
|
|
|
{% for location, opts in __location.iteritems() %}
|
|
|
|
location {{ location }} {
|
|
|
|
{% for opt in opts %}
|
|
|
|
{{ opt }}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
{% endfor %} # <-- Custom locations
|
|
|
|
{% endif %}
|
|
|
|
|
2015-07-30 18:02:21 +07:00
|
|
|
{% if item.use_access_log is defined and item.use_access_log %}
|
2015-08-01 05:05:30 +07:00
|
|
|
access_log {{ nginx_log_dir }}/{{ item.name[0] }}_access.log combined;
|
2015-07-30 18:02:21 +07:00
|
|
|
{% else %}
|
|
|
|
access_log off;
|
|
|
|
{% endif %}
|
|
|
|
{% if item.use_error_log is defined and item.use_error_log %}
|
2015-08-01 05:05:30 +07:00
|
|
|
error_log {{ nginx_log_dir }}/{{ item.name[0] }}_error.log {{ nginx_error_log_level }};
|
2015-07-30 18:02:21 +07:00
|
|
|
{% else %}
|
|
|
|
error_log off;
|
|
|
|
{% endif %}
|
|
|
|
}
|
|
|
|
|
2015-07-30 20:37:25 +07:00
|
|
|
{#
|
|
|
|
ssl on;
|
|
|
|
ssl_certificate {{ nginx_ssl_dir }}/{{ item.name }}/{{ item.name }}.crt;
|
|
|
|
ssl_certificate_key {{ nginx_ssl_dir }}/{{ item.name }}/{{ item.name }}.key;
|
|
|
|
include /etc/nginx/helpers/ssl-{{ item.ssl.template | default('strong') }};
|
|
|
|
#}
|
|
|
|
|
|
|
|
|
2015-07-30 18:02:21 +07:00
|
|
|
# HTTPS
|
|
|
|
#server {
|
|
|
|
#}
|
|
|
|
|
|
|
|
{% if item.redirect_from is defined and item.redirect_from is iterable %}
|
|
|
|
#
|
|
|
|
# Redirect from
|
|
|
|
#
|
|
|
|
server {
|
|
|
|
{% for port in __listen %}
|
|
|
|
listen {{ port }};
|
|
|
|
{% endfor %}
|
|
|
|
server_name {{ item.redirect_from | join(' ') }};
|
|
|
|
return 301 $scheme://{{ item.name[0] }}$request_uri;
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
# vim:filetype=nginx
|