Skip to content

Commit

Permalink
Allow customizing the try_files for the root location
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjj committed Nov 2, 2016
1 parent e293226 commit 1905339
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 6 additions & 2 deletions templates/etc/nginx/sites-available/default.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit 1905339

Please sign in to comment.