Skip to content

env variable to generate trailing slash in location directive #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ A docker image based on jwilder/nginx-proxy which modifies the template to have

* NGINX_PROXY_SUBDIRECTORY [REQUIRED]: Specifies the subdirectory to use for this container. If multiple containers have the same subdirectory, nginx will load balance those requests.
* NGINX_PROXY_SUBDIRECTORY_MAP_TO_ROOT: If 0, maps /$subdir to /$subdir. If 1, maps /$subdir to /. Defaults to 1.
* NGINX_PROXY_SUBDIRECTORY_TRAILING_SLASH: If 0, location is /$subdir. If 1, location is /$subdir/. Defaults to 1.
* VIRTUAL_PROTO: Protocol to use for connection to backend container. Defaults to http.
8 changes: 7 additions & 1 deletion nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ upstream {{ $subdir }} {

{{ define "locations" }}
{{ range $subdir, $containers := groupByMulti $ "Env.NGINX_PROXY_SUBDIRECTORY" "," }}
location /{{ $subdir }} {
{{ $trailing_slash := or (first (groupByKeys $containers "Env.NGINX_PROXY_SUBDIRECTORY_TRAILING_SLASH")) "1" }}
{{ if eq $trailing_slash "1" }}
location /{{ $subdir }}/ {
{{ else }}
location /{{ $subdir }} {
{{ end }}

{{ $proto := or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http" }}
{{ $map_to_root := or (first (groupByKeys $containers "Env.NGINX_PROXY_SUBDIRECTORY_MAP_TO_ROOT")) "1" }}
{{ if eq $map_to_root "1" }}
Expand Down