Removed VIRTUAL_PORT, now splits the VIRTUAL_HOST env on ':' and sets port to the last element in the returned slice

This commit is contained in:
Donal Byrne 2014-12-03 18:13:59 +01:00
parent 0580726415
commit 65e0dc0705
2 changed files with 11 additions and 5 deletions

View file

@ -16,7 +16,11 @@ Provided your DNS is setup to forward foo.bar.com to the a host running nginx-pr
### Multiple Ports
If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected.
If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can add VIRTUAL_HOST as <host>:<port>.
$ docker run -e VIRTUAL_HOST=foo.bar.com:8080 ...
If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected.
[1]: https://github.com/jwilder/docker-gen
[2]: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/

View file

@ -35,7 +35,9 @@ server {
return 503;
}
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
{{ range $hostfull, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
{{ $host := first ( split $hostfull ":" ) }}
{{ $port := last ( split $hostfull ":" ) }}
upstream {{ $host }} {
{{ range $container := $containers }}
@ -46,10 +48,10 @@ upstream {{ $host }} {
# {{$container.Name}}
server {{ $address.IP }}:{{ $address.Port }};
{{ end }}
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
{{ else if $container.Env.VIRTUAL_PORT }}
{{/* If more than one port exposed, use the one matching after the colon in VIRTUAL_HOST env var */}}
{{ else if $port }}
{{ range $address := .Addresses }}
{{ if eq $address.Port $container.Env.VIRTUAL_PORT }}
{{ if eq $address.Port $port }}
# {{$container.Name}}
server {{ $address.IP }}:{{ $address.Port }};
{{ end }}