This commit is contained in:
Donal Byrne 2015-07-17 06:47:50 +00:00
commit 3c057e2277
2 changed files with 11 additions and 5 deletions

View file

@ -18,7 +18,11 @@ Provided your DNS is setup to forward foo.bar.com to the a host running nginx-pr
### Multiple Ports ### 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 [1]: https://github.com/jwilder/docker-gen
[2]: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/ [2]: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/

View file

@ -37,7 +37,9 @@ server {
return 503; 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 }} { upstream {{ $host }} {
{{ range $container := $containers }} {{ range $container := $containers }}
@ -48,10 +50,10 @@ upstream {{ $host }} {
# {{$container.Name}} # {{$container.Name}}
server {{ $address.IP }}:{{ $address.Port }}; server {{ $address.IP }}:{{ $address.Port }};
{{ end }} {{ end }}
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}} {{/* If more than one port exposed, use the one matching after the colon in VIRTUAL_HOST env var */}}
{{ else if $container.Env.VIRTUAL_PORT }} {{ else if (and ($port ) (ne $port $host) ) }}
{{ range $address := .Addresses }} {{ range $address := .Addresses }}
{{ if eq $address.Port $container.Env.VIRTUAL_PORT }} {{ if eq $address.Port $port }}
# {{$container.Name}} # {{$container.Name}}
server {{ $address.IP }}:{{ $address.Port }}; server {{ $address.IP }}:{{ $address.Port }};
{{ end }} {{ end }}