forked from nginx-proxy/nginx-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dockergen: docker-gen -watch -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf | ||
nginx: nginx | ||
dockergen: docker-gen -config /app/docker-gen.cfg | ||
nginx: nginx-debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
version: '2' | ||
services: | ||
nginx-proxy: | ||
image: jwilder/nginx-proxy | ||
container_name: nginx-proxy | ||
build: . | ||
ports: | ||
- "80:80" | ||
- "180:80" | ||
- "81:81" | ||
volumes: | ||
- /var/run/docker.sock:/tmp/docker.sock:ro | ||
|
||
whoami: | ||
image: jwilder/whoami | ||
environment: | ||
- VIRTUAL_HOST=whoami.local | ||
- VIRTUAL_HOST=whoami.loc | ||
|
||
mysql: | ||
image: mysql:5.6 | ||
environment: | ||
VIRTUAL_TCP_HOST: whoami.loc | ||
VIRTUAL_TCP_PORT: 3306 | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[[config]] | ||
template = "/app/nginx.tmpl" | ||
dest = "/etc/nginx/conf.d/default.conf" | ||
notifycmd = "nginx-debug -s reload" | ||
watch = true | ||
|
||
[[config]] | ||
template = "/app/nginx.stream.tmpl" | ||
dest = "/etc/nginx/stream.conf.d/default.conf" | ||
notifycmd = "nginx-debug -s reload" | ||
watch = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }} | ||
|
||
{{ define "upstream" }} | ||
{{ if .Address }} | ||
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}} | ||
{{ if and .Container.Node.ID .Address.HostPort }} | ||
# {{ .Container.Node.Name }}/{{ .Container.Name }} | ||
server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }}; | ||
{{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}} | ||
{{ else if .Network }} | ||
# {{ .Container.Name }} | ||
server {{ .Network.IP }}:{{ .Address.Port }}; | ||
{{ end }} | ||
{{ else if .Network }} | ||
# {{ .Container.Name }} | ||
server {{ .Network.IP }} down; | ||
{{ end }} | ||
{{ end }} | ||
|
||
access_log off; | ||
error_log /var/log/nginx/debug.log debug; | ||
|
||
{{ if $.Env.RESOLVERS }} | ||
resolver {{ $.Env.RESOLVERS }}; | ||
{{ end }} | ||
|
||
{{ $enable_ipv6 := eq (or ($.Env.ENABLE_IPV6) "") "true" }} | ||
|
||
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_TCP_HOST" "," }} | ||
|
||
{{ $host := trim $host }} | ||
{{ $is_regexp := hasPrefix "~" $host }} | ||
{{ $upstream_name := when $is_regexp (sha1 $host) $host }} | ||
|
||
# {{ $host }} | ||
upstream {{ $upstream_name }} { | ||
|
||
{{ range $container := $containers }} | ||
{{ $addrLen := len $container.Addresses }} | ||
|
||
{{ range $knownNetwork := $CurrentContainer.Networks }} | ||
{{ range $containerNetwork := $container.Networks }} | ||
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }} | ||
## Can be connect with "{{ $containerNetwork.Name }}" network | ||
|
||
{{/* If only 1 port exposed, use that */}} | ||
{{ if eq $addrLen 1 }} | ||
{{ $address := index $container.Addresses 0 }} | ||
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }} | ||
{{/* If more than one port exposed, use the one matching VIRTUAL_TCP_PORT env var, falling back to standard web port 81 */}} | ||
{{ else }} | ||
{{ $port := coalesce $container.Env.VIRTUAL_TCP_PORT "81" }} | ||
{{ $address := where $container.Addresses "Port" $port | first }} | ||
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }} | ||
{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
} | ||
|
||
server { | ||
listen {{ $host }}:81; | ||
proxy_pass {{ trim $upstream_name }}; | ||
} | ||
|
||
{{ end }} |