Update the nginx template to support virtual path by creating named upstreams and targetting them appropriately
This commit is contained in:
parent
e762468759
commit
fecd2713fe
1 changed files with 21 additions and 12 deletions
33
nginx.tmpl
33
nginx.tmpl
|
@ -169,10 +169,9 @@ server {
|
|||
{{ $is_regexp := hasPrefix "~" $host }}
|
||||
{{ $upstream_name := when $is_regexp (sha1 $host) $host }}
|
||||
|
||||
# {{ $host }}
|
||||
upstream {{ $upstream_name }} {
|
||||
|
||||
{{ range $container := $containers }}
|
||||
# {{ $container.Name }}
|
||||
upstream {{ $container.Name }} {
|
||||
{{ $addrLen := len $container.Addresses }}
|
||||
|
||||
{{ range $knownNetwork := $CurrentContainer.Networks }}
|
||||
|
@ -196,8 +195,8 @@ upstream {{ $upstream_name }} {
|
|||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ $default_host := or ($.Env.DEFAULT_HOST) "" }}
|
||||
{{ $default_server := index (dict $host "" $default_host "default_server") $host }}
|
||||
|
@ -292,16 +291,19 @@ server {
|
|||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
location / {
|
||||
{{ range $container := $containers }}
|
||||
{{/* Determine whether this container has specified a virtual path, or default to the / pattern */}}
|
||||
{{ $location := coalesce $container.Env.VIRTUAL_PATH "/" }}
|
||||
location {{ $location }} {
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||
{{ else if eq $proto "fastcgi" }}
|
||||
root {{ trim $vhost_root }};
|
||||
include fastcgi_params;
|
||||
fastcgi_pass {{ trim $upstream_name }};
|
||||
fastcgi_pass {{ trim $container.Name }};
|
||||
{{ else }}
|
||||
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
proxy_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||
{{ end }}
|
||||
|
||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||
|
@ -314,6 +316,7 @@ server {
|
|||
include /etc/nginx/vhost.d/default_location;
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
|
@ -339,16 +342,20 @@ server {
|
|||
include /etc/nginx/vhost.d/default;
|
||||
{{ end }}
|
||||
|
||||
location / {
|
||||
{{ range $container := $containers }}
|
||||
{{/* Determine whether this container has specified a virtual path, or default to the / pattern */}}
|
||||
{{ $location := coalesce $container.Env.VIRTUAL_PATH "/" }}
|
||||
|
||||
location {{ $location }} {
|
||||
{{ if eq $proto "uwsgi" }}
|
||||
include uwsgi_params;
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
uwsgi_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||
{{ else if eq $proto "fastcgi" }}
|
||||
root {{ trim $vhost_root }};
|
||||
include fastcgi_params;
|
||||
fastcgi_pass {{ trim $upstream_name }};
|
||||
fastcgi_pass {{ trim $container.Name }};
|
||||
{{ else }}
|
||||
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
||||
proxy_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||
{{ end }}
|
||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||
auth_basic "Restricted {{ $host }}";
|
||||
|
@ -360,6 +367,8 @@ server {
|
|||
include /etc/nginx/vhost.d/default_location;
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
|
||||
|
|
Loading…
Reference in a new issue