mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-08-23 07:51:56 +00:00
feat: allow nginx / docker-gen network segregation
* fix merge conflicts
This commit is contained in:
@@ -1157,6 +1157,12 @@ Finally, start your containers with `VIRTUAL_HOST` environment variables.
|
|||||||
docker run -e VIRTUAL_HOST=foo.bar.com ...
|
docker run -e VIRTUAL_HOST=foo.bar.com ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To allow for network segregation of the nginx and docker-gen containers, the label `com.github.nginx-proxy.nginx-proxy.nginx` must be applied to the nginx container, otherwise it is assumed that nginx and docker-gen share the same network:
|
||||||
|
|
||||||
|
```console
|
||||||
|
docker run -d -p 80:80 --name nginx -l "com.github.nginx-proxy.nginx-proxy.nginx" -v /tmp/nginx:/etc/nginx/conf.d -t nginx
|
||||||
|
```
|
||||||
|
|
||||||
⬆️ [back to table of contents](#table-of-contents)
|
⬆️ [back to table of contents](#table-of-contents)
|
||||||
|
|
||||||
## Docker Compose
|
## Docker Compose
|
||||||
|
30
nginx.tmpl
30
nginx.tmpl
@@ -11,6 +11,7 @@
|
|||||||
{{- $_ := set $globals "Env" $.Env }}
|
{{- $_ := set $globals "Env" $.Env }}
|
||||||
{{- $_ := set $globals "Docker" $.Docker }}
|
{{- $_ := set $globals "Docker" $.Docker }}
|
||||||
{{- $_ := set $globals "CurrentContainer" (where $globals.containers "ID" $globals.Docker.CurrentContainerID | first) }}
|
{{- $_ := set $globals "CurrentContainer" (where $globals.containers "ID" $globals.Docker.CurrentContainerID | first) }}
|
||||||
|
{{- $_ := set $globals "NginxContainer" (whereLabelExists $globals.containers "com.github.nginx-proxy.nginx-proxy.nginx" | first) }}
|
||||||
|
|
||||||
{{- $config := dict }}
|
{{- $config := dict }}
|
||||||
{{- $_ := set $config "nginx_proxy_version" $.Env.NGINX_PROXY_VERSION }}
|
{{- $_ := set $config "nginx_proxy_version" $.Env.NGINX_PROXY_VERSION }}
|
||||||
@@ -44,14 +45,21 @@
|
|||||||
|
|
||||||
{{- $_ := set $globals "vhosts" (dict) }}
|
{{- $_ := set $globals "vhosts" (dict) }}
|
||||||
{{- $_ := set $globals "networks" (dict) }}
|
{{- $_ := set $globals "networks" (dict) }}
|
||||||
# Networks available to the container running docker-gen (which are assumed to
|
# Networks available to the container labeled "com.github.nginx-proxy.nginx-proxy.nginx" or the one running docker-gen (which are assumed to
|
||||||
# match the networks available to the container running nginx):
|
# match the networks available to the container running nginx):
|
||||||
{{- /*
|
{{- /*
|
||||||
* Note: $globals.CurrentContainer may be nil in some circumstances due to
|
* Note: $globals.CurrentContainer may be nil in some circumstances due to
|
||||||
* <https://github.com/nginx-proxy/docker-gen/issues/458>. For more context
|
* <https://github.com/nginx-proxy/docker-gen/issues/458>. For more context
|
||||||
* see <https://github.com/nginx-proxy/nginx-proxy/issues/2189>.
|
* see <https://github.com/nginx-proxy/nginx-proxy/issues/2189>.
|
||||||
*/}}
|
*/}}
|
||||||
{{- if $globals.CurrentContainer }}
|
{{- if $globals.NginxContainer }}
|
||||||
|
{{- range sortObjectsByKeysAsc $globals.NginxContainer.Networks "Name" }}
|
||||||
|
{{- $_ := set $globals.networks .Name . }}
|
||||||
|
# {{ .Name }}
|
||||||
|
{{- else }}
|
||||||
|
# (none)
|
||||||
|
{{- end }}
|
||||||
|
{{- else if $globals.CurrentContainer }}
|
||||||
{{- range sortObjectsByKeysAsc $globals.CurrentContainer.Networks "Name" }}
|
{{- range sortObjectsByKeysAsc $globals.CurrentContainer.Networks "Name" }}
|
||||||
{{- $_ := set $globals.networks .Name . }}
|
{{- $_ := set $globals.networks .Name . }}
|
||||||
# {{ .Name }}
|
# {{ .Name }}
|
||||||
@@ -97,11 +105,21 @@
|
|||||||
{{- $ipv4 = "127.0.0.1" }}
|
{{- $ipv4 = "127.0.0.1" }}
|
||||||
{{- continue }}
|
{{- continue }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- range sortObjectsByKeysAsc $.globals.CurrentContainer.Networks "Name" }}
|
{{- if $.globals.NginxContainer }}
|
||||||
{{- if and . .Gateway (not .Internal) }}
|
{{- range sortObjectsByKeysAsc $.globals.NginxContainer.Networks "Name" }}
|
||||||
|
{{- if and . .Gateway (not .Internal) }}
|
||||||
# container is in host network mode, using {{ .Name }} gateway IP
|
# container is in host network mode, using {{ .Name }} gateway IP
|
||||||
{{- $ipv4 = .Gateway }}
|
{{- $ipv4 = .Gateway }}
|
||||||
{{- break }}
|
{{- break }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- range sortObjectsByKeysAsc $.globals.CurrentContainer.Networks "Name" }}
|
||||||
|
{{- if and . .Gateway (not .Internal) }}
|
||||||
|
# container is in host network mode, using {{ .Name }} gateway IP
|
||||||
|
{{- $ipv4 = .Gateway }}
|
||||||
|
{{- break }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if $ipv4 }}
|
{{- if $ipv4 }}
|
||||||
|
Reference in New Issue
Block a user