commit
9d7443dbd8
1 changed files with 63 additions and 12 deletions
75
nginx.tmpl
75
nginx.tmpl
|
@ -169,10 +169,9 @@ server {
|
||||||
{{ $is_regexp := hasPrefix "~" $host }}
|
{{ $is_regexp := hasPrefix "~" $host }}
|
||||||
{{ $upstream_name := when $is_regexp (sha1 $host) $host }}
|
{{ $upstream_name := when $is_regexp (sha1 $host) $host }}
|
||||||
|
|
||||||
# {{ $host }}
|
|
||||||
upstream {{ $upstream_name }} {
|
|
||||||
|
|
||||||
{{ range $container := $containers }}
|
{{ range $container := $containers }}
|
||||||
|
# {{ $container.Name }}
|
||||||
|
upstream {{ $container.Name }} {
|
||||||
{{ $addrLen := len $container.Addresses }}
|
{{ $addrLen := len $container.Addresses }}
|
||||||
|
|
||||||
{{ range $knownNetwork := $CurrentContainer.Networks }}
|
{{ range $knownNetwork := $CurrentContainer.Networks }}
|
||||||
|
@ -196,8 +195,8 @@ upstream {{ $upstream_name }} {
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
|
||||||
}
|
}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ $default_host := or ($.Env.DEFAULT_HOST) "" }}
|
{{ $default_host := or ($.Env.DEFAULT_HOST) "" }}
|
||||||
{{ $default_server := index (dict $host "" $default_host "default_server") $host }}
|
{{ $default_server := index (dict $host "" $default_host "default_server") $host }}
|
||||||
|
@ -292,16 +291,40 @@ server {
|
||||||
include /etc/nginx/vhost.d/default;
|
include /etc/nginx/vhost.d/default;
|
||||||
{{ end }}
|
{{ 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 "/" }}
|
||||||
|
{{ $is_regexp := hasPrefix "^" $location }}
|
||||||
|
{{ $modifier := when $is_regexp "~" "" }}
|
||||||
|
|
||||||
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
location {{ $modifier }} '{{ $location }}' {
|
||||||
|
return 302 '{{ $location }}/';
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
location {{ $modifier }} '{{ $location }}/' {
|
||||||
|
{{ else }}
|
||||||
|
location {{ $modifier }} '{{ $location }}' {
|
||||||
|
{{ end }}
|
||||||
{{ if eq $proto "uwsgi" }}
|
{{ if eq $proto "uwsgi" }}
|
||||||
include uwsgi_params;
|
include uwsgi_params;
|
||||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
uwsgi_pass {{ trim $proto }}://{{ trim $container.Name }}/;
|
||||||
|
{{ else }}
|
||||||
|
uwsgi_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||||
|
{{ end }}
|
||||||
{{ else if eq $proto "fastcgi" }}
|
{{ else if eq $proto "fastcgi" }}
|
||||||
root {{ trim $vhost_root }};
|
root {{ trim $vhost_root }};
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_pass {{ trim $upstream_name }};
|
fastcgi_pass {{ trim $container.Name }};
|
||||||
{{ else }}
|
{{ else }}
|
||||||
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
proxy_pass {{ trim $proto }}://{{ trim $container.Name }}/;
|
||||||
|
{{ else }}
|
||||||
|
proxy_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||||
|
@ -314,6 +337,7 @@ server {
|
||||||
include /etc/nginx/vhost.d/default_location;
|
include /etc/nginx/vhost.d/default_location;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -339,16 +363,41 @@ server {
|
||||||
include /etc/nginx/vhost.d/default;
|
include /etc/nginx/vhost.d/default;
|
||||||
{{ end }}
|
{{ 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 "/" }}
|
||||||
|
|
||||||
|
{{ $is_regexp := hasPrefix "^" $location }}
|
||||||
|
{{ $modifier := when $is_regexp "~" "" }}
|
||||||
|
|
||||||
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
location {{ $modifier }} '{{ $location }}' {
|
||||||
|
return 302 '{{ $location }}/';
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
location {{ $modifier }} '{{ $location }}/' {
|
||||||
|
{{ else }}
|
||||||
|
location {{ $modifier }} '{{ $location }}' {
|
||||||
|
{{ end }}
|
||||||
{{ if eq $proto "uwsgi" }}
|
{{ if eq $proto "uwsgi" }}
|
||||||
include uwsgi_params;
|
include uwsgi_params;
|
||||||
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
uwsgi_pass {{ trim $proto }}://{{ trim $container.Name }}/;
|
||||||
|
{{ else }}
|
||||||
|
uwsgi_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||||
|
{{ end }}
|
||||||
{{ else if eq $proto "fastcgi" }}
|
{{ else if eq $proto "fastcgi" }}
|
||||||
root {{ trim $vhost_root }};
|
root {{ trim $vhost_root }};
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_pass {{ trim $upstream_name }};
|
fastcgi_pass {{ trim $container.Name }};
|
||||||
{{ else }}
|
{{ else }}
|
||||||
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
|
{{ if (eq (or ($container.Env.VIRTUAL_PATH_STRIP) "") "true") }}
|
||||||
|
proxy_pass {{ trim $proto }}://{{ trim $container.Name }}/;
|
||||||
|
{{ else }}
|
||||||
|
proxy_pass {{ trim $proto }}://{{ trim $container.Name }};
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
|
||||||
auth_basic "Restricted {{ $host }}";
|
auth_basic "Restricted {{ $host }}";
|
||||||
|
@ -360,6 +409,8 @@ server {
|
||||||
include /etc/nginx/vhost.d/default_location;
|
include /etc/nginx/vhost.d/default_location;
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
|
{{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
|
||||||
|
|
Loading…
Reference in a new issue