mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 09:48:14 +00:00
Merge pull request #2141 from rhansen/debug
feat: Unconditionally produce debug comments
This commit is contained in:
commit
98b6473c84
@ -490,12 +490,13 @@ Please note that using regular expressions in `VIRTUAL_HOST` will always result
|
|||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
In case you can't access your VIRTUAL_HOST, set `DEBUG=true` in the client container's environment and have a look at the generated nginx configuration file `/etc/nginx/conf.d/default.conf`:
|
If you can't access your `VIRTUAL_HOST`, inspect the generated nginx configuration:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
docker exec <nginx-proxy-instance> cat /etc/nginx/conf.d/default.conf
|
docker exec <nginx-proxy-instance> nginx -T
|
||||||
```
|
```
|
||||||
Especially at `upstream` definition blocks which should look like:
|
|
||||||
|
Pay attention to the `upstream` definition blocks, which should look like this:
|
||||||
|
|
||||||
```Nginx
|
```Nginx
|
||||||
# foo.example.com
|
# foo.example.com
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
{{- $_ := set $globals "nginx_proxy_version" (coalesce $globals.Env.NGINX_PROXY_VERSION "") }}
|
{{- $_ := set $globals "nginx_proxy_version" (coalesce $globals.Env.NGINX_PROXY_VERSION "") }}
|
||||||
{{- $_ := set $globals "external_http_port" (coalesce $globals.Env.HTTP_PORT "80") }}
|
{{- $_ := set $globals "external_http_port" (coalesce $globals.Env.HTTP_PORT "80") }}
|
||||||
{{- $_ := set $globals "external_https_port" (coalesce $globals.Env.HTTPS_PORT "443") }}
|
{{- $_ := set $globals "external_https_port" (coalesce $globals.Env.HTTPS_PORT "443") }}
|
||||||
{{- $_ := set $globals "debug_all" $globals.Env.DEBUG }}
|
|
||||||
{{- $_ := set $globals "sha1_upstream_name" (parseBool (coalesce $globals.Env.SHA1_UPSTREAM_NAME "false")) }}
|
{{- $_ := set $globals "sha1_upstream_name" (parseBool (coalesce $globals.Env.SHA1_UPSTREAM_NAME "false")) }}
|
||||||
{{- $_ := set $globals "default_root_response" (coalesce $globals.Env.DEFAULT_ROOT "404") }}
|
{{- $_ := set $globals "default_root_response" (coalesce $globals.Env.DEFAULT_ROOT "404") }}
|
||||||
{{- $_ := set $globals "trust_downstream_proxy" (parseBool (coalesce $globals.Env.TRUST_DOWNSTREAM_PROXY "true")) }}
|
{{- $_ := set $globals "trust_downstream_proxy" (parseBool (coalesce $globals.Env.TRUST_DOWNSTREAM_PROXY "true")) }}
|
||||||
@ -106,23 +105,19 @@
|
|||||||
|
|
||||||
{{- define "upstream" }}
|
{{- define "upstream" }}
|
||||||
{{- $networks := .Networks }}
|
{{- $networks := .Networks }}
|
||||||
{{- $debug_all := .Debug }}
|
|
||||||
upstream {{ .Upstream }} {
|
upstream {{ .Upstream }} {
|
||||||
{{- $server_found := false }}
|
{{- $server_found := false }}
|
||||||
{{- range $container := .Containers }}
|
{{- range $container := .Containers }}
|
||||||
{{- $debug := parseBool (coalesce $container.Env.DEBUG $debug_all "false") }}
|
|
||||||
{{- /* If only 1 port exposed, use that as a default, else 80 */}}
|
{{- /* If only 1 port exposed, use that as a default, else 80 */}}
|
||||||
{{- $defaultPort := (when (eq (len $container.Addresses) 1) (first $container.Addresses) (dict "Port" "80")).Port }}
|
{{- $defaultPort := (when (eq (len $container.Addresses) 1) (first $container.Addresses) (dict "Port" "80")).Port }}
|
||||||
{{- $port := (coalesce $container.Env.VIRTUAL_PORT $defaultPort) }}
|
{{- $port := (coalesce $container.Env.VIRTUAL_PORT $defaultPort) }}
|
||||||
{{- $address := where $container.Addresses "Port" $port | first }}
|
{{- $address := where $container.Addresses "Port" $port | first }}
|
||||||
{{- if $debug }}
|
|
||||||
# Exposed ports: {{ $container.Addresses }}
|
# Exposed ports: {{ $container.Addresses }}
|
||||||
# Default virtual port: {{ $defaultPort }}
|
# Default virtual port: {{ $defaultPort }}
|
||||||
# VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }}
|
# VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }}
|
||||||
{{- if not $address }}
|
{{- if not $address }}
|
||||||
# /!\ Virtual port not exposed
|
# /!\ Virtual port not exposed
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
|
||||||
{{- range $knownNetwork := $networks }}
|
{{- range $knownNetwork := $networks }}
|
||||||
{{- range $containerNetwork := sortObjectsByKeysAsc $container.Networks "Name" }}
|
{{- range $containerNetwork := sortObjectsByKeysAsc $container.Networks "Name" }}
|
||||||
{{- if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
|
{{- if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
|
||||||
@ -292,7 +287,7 @@ server {
|
|||||||
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
{{- $upstream = printf "%s-%s" $upstream $sum }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
# {{ $host }}{{ $path }}
|
# {{ $host }}{{ $path }}
|
||||||
{{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $globals.CurrentContainer.Networks "Debug" $globals.debug_all) }}
|
{{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $globals.CurrentContainer.Networks) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- $default_host := or ($globals.Env.DEFAULT_HOST) "" }}
|
{{- $default_host := or ($globals.Env.DEFAULT_HOST) "" }}
|
||||||
|
@ -10,8 +10,6 @@ web:
|
|||||||
reverseproxy:
|
reverseproxy:
|
||||||
image: nginxproxy/nginx-proxy:test
|
image: nginxproxy/nginx-proxy:test
|
||||||
container_name: reverseproxy
|
container_name: reverseproxy
|
||||||
environment:
|
|
||||||
DEBUG: "true"
|
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
- ./tmp_certs:/etc/nginx/certs:ro
|
- ./tmp_certs:/etc/nginx/certs:ro
|
@ -1,12 +0,0 @@
|
|||||||
import pytest
|
|
||||||
import re
|
|
||||||
|
|
||||||
def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
|
|
||||||
conf = nginxproxy.get_conf().decode('ASCII')
|
|
||||||
assert re.search(r"# Exposed ports: \[\{[^}]+\s+80\s+tcp \} \{[^}]+\s+81\s+tcp \}\]", conf) or \
|
|
||||||
re.search(r"# Exposed ports: \[\{[^}]+\s+81\s+tcp \} \{[^}]+\s+80\s+tcp \}\]", conf)
|
|
||||||
assert re.search(r"# Exposed ports: \[\{[^}]+\s+82\s+tcp \} \{[^}]+\s+83\s+tcp \}\]", conf) or \
|
|
||||||
re.search(r"# Exposed ports: \[\{[^}]+\s+83\s+tcp \} \{[^}]+\s+82\s+tcp \}\]", conf)
|
|
||||||
assert "# Default virtual port: 80" in conf
|
|
||||||
assert "# VIRTUAL_PORT: 82" in conf
|
|
||||||
assert conf.count("# /!\\ Virtual port not exposed") == 1
|
|
@ -1,26 +0,0 @@
|
|||||||
web1:
|
|
||||||
image: web
|
|
||||||
expose:
|
|
||||||
- "80"
|
|
||||||
- "81"
|
|
||||||
environment:
|
|
||||||
WEB_PORTS: "80 81"
|
|
||||||
VIRTUAL_HOST: "web1.nginx-proxy.tld"
|
|
||||||
VIRTUAL_PORT: "82"
|
|
||||||
|
|
||||||
web2:
|
|
||||||
image: web
|
|
||||||
expose:
|
|
||||||
- "82"
|
|
||||||
- "83"
|
|
||||||
environment:
|
|
||||||
WEB_PORTS: "82 83"
|
|
||||||
VIRTUAL_HOST: "web2.nginx-proxy.tld"
|
|
||||||
VIRTUAL_PORT: "82"
|
|
||||||
|
|
||||||
sut:
|
|
||||||
image: nginxproxy/nginx-proxy:test
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
|
||||||
environment:
|
|
||||||
DEBUG: "true"
|
|
@ -1,8 +0,0 @@
|
|||||||
import pytest
|
|
||||||
import re
|
|
||||||
|
|
||||||
def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
|
|
||||||
conf = nginxproxy.get_conf().decode('ASCII')
|
|
||||||
assert re.search(r"# Exposed ports: \[\{[^}]+\s+80\s+tcp \} \{[^}]+\s+81\s+tcp \}\]", conf) or \
|
|
||||||
re.search(r"# Exposed ports: \[\{[^}]+\s+81\s+tcp \} \{[^}]+\s+80\s+tcp \}\]", conf)
|
|
||||||
assert conf.count("# Exposed ports: [{") == 1
|
|
@ -1,25 +0,0 @@
|
|||||||
web1:
|
|
||||||
image: web
|
|
||||||
expose:
|
|
||||||
- "80"
|
|
||||||
- "81"
|
|
||||||
environment:
|
|
||||||
WEB_PORTS: "80 81"
|
|
||||||
VIRTUAL_HOST: "web1.nginx-proxy.tld"
|
|
||||||
VIRTUAL_PORT: "82"
|
|
||||||
DEBUG: "true"
|
|
||||||
|
|
||||||
web2:
|
|
||||||
image: web
|
|
||||||
expose:
|
|
||||||
- "82"
|
|
||||||
- "83"
|
|
||||||
environment:
|
|
||||||
WEB_PORTS: "82 83"
|
|
||||||
VIRTUAL_HOST: "web2.nginx-proxy.tld"
|
|
||||||
VIRTUAL_PORT: "82"
|
|
||||||
|
|
||||||
sut:
|
|
||||||
image: nginxproxy/nginx-proxy:test
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
|
Loading…
x
Reference in New Issue
Block a user