diff --git a/README.md b/README.md index 11891d7..1fcd9a8 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,9 @@ nginx_default_sites: # return; # } custom_locations: '' + # If you want to override the default / location's try_files, this is the + # place to do it. This could be useful for php-fpm based virtual hosts. + custom_root_location_try_files: '' disallow_hidden_files: # Block all hidden files and directories, disable at your own risk. enabled: True diff --git a/defaults/main.yml b/defaults/main.yml index ed1efeb..7edb00e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -54,11 +54,12 @@ nginx_default_sites: pattern: ' ~ ^/assets/' expires: 'max' custom_locations: '' + custom_root_location_try_files: '' disallow_hidden_files: enabled: True upstreams: [] -nginx_upstream_proxy_settings: +nginx_default_upstream_proxy_settings: - 'proxy_set_header X-Real-IP $remote_addr' - 'proxy_set_header X-Forwarded-Proto $scheme' - 'proxy_set_header Host $http_host' diff --git a/templates/etc/nginx/sites-available/default.conf.j2 b/templates/etc/nginx/sites-available/default.conf.j2 index 4d6f47d..73568de 100644 --- a/templates/etc/nginx/sites-available/default.conf.j2 +++ b/templates/etc/nginx/sites-available/default.conf.j2 @@ -100,14 +100,18 @@ server { } location / { +{% if item.custom_root_location_try_files %} + try_files {{ item.custom_root_location_try_files }}; +{% else %} try_files $uri $uri.html $uri/{{ (' @' + item.upstreams[0].name) if (item.upstreams) else '' }} =404; +{% endif %} } {% if item.upstreams %} {% for upstream in item.upstreams %} location @{{ upstream.name }} { -{% if nginx_upstream_proxy_settings is iterable -%} -{% for key in nginx_upstream_proxy_settings %} +{% if nginx_default_upstream_proxy_settings is iterable -%} +{% for key in nginx_default_upstream_proxy_settings %} {{ key }}; {% endfor %} {% endif %}