ansible-infra/roles/nginx/templates/nginx.conf.j2

39 lines
1.1 KiB
Django/Jinja

{{ ansible_managed | comment }}
{% if nginx_server.name is defined %}
server {
listen {{ nginx_server.port }};
server_name {{ nginx_server.name }};
{% endif %}
{% for location in nginx_server.locations | default([]) %}
location {{ location.path }} {
{% if location.proxy_pass is defined %}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
{% endif %}
{% if location.basic_auth.file is defined %}
auth_basic "Authentication required";
auth_basic_user_file /etc/nginx/{{ location.basic_auth.file }};
{% endif %}
{% if location.proxy_pass is defined %}
proxy_pass http://localhost:{{ location.proxy_pass.port | default('80') }}{{ location.proxy_pass.path }};
{% endif %}
{% if location.return is defined %}
return {{ location.return.code }} {{ location.return.url }};
{% endif %}
}
{% endfor %}
{% if nginx_server.name is defined %}
{% for include_path in nginx_server.includes | default([]) %}
include {{ include_path }};
{% endfor %}
}
{% endif %}