Merge pull request #3 from KeyWeeUsr/virtualpath

Virtualpath
This commit is contained in:
Constantin 2020-01-23 20:23:50 +01:00 committed by GitHub
commit 9d7443dbd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,40 @@ 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 "/" }}
{{ $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" }}
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" }}
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 }};
{{ 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 }}
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
@ -314,6 +337,7 @@ server {
include /etc/nginx/vhost.d/default_location;
{{ end }}
}
{{ end }}
}
{{ end }}
@ -339,16 +363,41 @@ 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 "/" }}
{{ $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" }}
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" }}
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 }};
{{ 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 }}
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
auth_basic "Restricted {{ $host }}";
@ -360,6 +409,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")) }}