mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
feat: Add user customizable default root response
This commit is contained in:
parent
28c73e5b52
commit
9df330e51e
@ -1,5 +1,5 @@
|
|||||||
# setup build arguments for version of dependencies to use
|
# setup build arguments for version of dependencies to use
|
||||||
ARG DOCKER_GEN_VERSION=0.7.7
|
ARG DOCKER_GEN_VERSION=main
|
||||||
ARG FOREGO_VERSION=v0.17.0
|
ARG FOREGO_VERSION=v0.17.0
|
||||||
|
|
||||||
# Use a specific version of golang to build both binaries
|
# Use a specific version of golang to build both binaries
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# setup build arguments for version of dependencies to use
|
# setup build arguments for version of dependencies to use
|
||||||
ARG DOCKER_GEN_VERSION=0.7.7
|
ARG DOCKER_GEN_VERSION=main
|
||||||
ARG FOREGO_VERSION=v0.17.0
|
ARG FOREGO_VERSION=v0.17.0
|
||||||
|
|
||||||
# Use a specific version of golang to build both binaries
|
# Use a specific version of golang to build both binaries
|
||||||
|
10
README.md
10
README.md
@ -123,6 +123,16 @@ You can have multiple containers proxied by the same `VIRTUAL_HOST` by adding a
|
|||||||
|
|
||||||
The full request URI will be forwarded to the serving container in the `X-Forwarded-Path` header.
|
The full request URI will be forwarded to the serving container in the `X-Forwarded-Path` header.
|
||||||
|
|
||||||
|
**NOTE**: Your application needs to be able to generate links starting with `VIRTUAL_PATH`. This can be achieved by it being natively on this path or havin an option to prepend this path. The application does not need to expect this path in the request.
|
||||||
|
|
||||||
|
#### DEFAULT_ROOT
|
||||||
|
|
||||||
|
This environment variable of the nginx proxy container can be used to customize the return error page if no matching path is found. Furthermore it is possible to use anything which is compatible with the `return` statement of nginx.
|
||||||
|
|
||||||
|
For example `DEFAUL_ROOT=418` will return a 418 error page instead of the normal 404 one.
|
||||||
|
Another example is `DEFAULT_ROOT="301 https://github.com/nginx-proxy/nginx-proxy/blob/main/README.md"` which would redirect an invalid request to this documentation.
|
||||||
|
|
||||||
|
|
||||||
### Multiple Networks
|
### Multiple Networks
|
||||||
|
|
||||||
With the addition of [overlay networking](https://docs.docker.com/engine/userguide/networking/get-started-overlay/) in Docker 1.9, your `nginx-proxy` container may need to connect to backend containers on multiple networks. By default, if you don't pass the `--net` flag when your `nginx-proxy` container is created, it will only be attached to the default `bridge` network. This means that it will not be able to connect to containers on networks other than `bridge`.
|
With the addition of [overlay networking](https://docs.docker.com/engine/userguide/networking/get-started-overlay/) in Docker 1.9, your `nginx-proxy` container may need to connect to backend containers on multiple networks. By default, if you don't pass the `--net` flag when your `nginx-proxy` container is created, it will only be attached to the default `bridge` network. This means that it will not be able to connect to containers on networks other than `bridge`.
|
||||||
|
11
nginx.tmpl
11
nginx.tmpl
@ -5,6 +5,7 @@
|
|||||||
{{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }}
|
{{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }}
|
||||||
{{ $debug_all := $.Env.DEBUG }}
|
{{ $debug_all := $.Env.DEBUG }}
|
||||||
{{ $sha1_upstream_name := parseBool (coalesce $.Env.SHA1_UPSTREAM_NAME "false") }}
|
{{ $sha1_upstream_name := parseBool (coalesce $.Env.SHA1_UPSTREAM_NAME "false") }}
|
||||||
|
{{ $default_root_response := coalesce $.Env.DEFAULT_ROOT "404" }}
|
||||||
|
|
||||||
{{ define "ssl_policy" }}
|
{{ define "ssl_policy" }}
|
||||||
{{ if eq .ssl_policy "Mozilla-Modern" }}
|
{{ if eq .ssl_policy "Mozilla-Modern" }}
|
||||||
@ -392,6 +393,11 @@ server {
|
|||||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||||
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "Vhostroot" $vhost_root) }}
|
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "Vhostroot" $vhost_root) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if (not (contains $paths "/")) }}
|
||||||
|
location / {
|
||||||
|
return {{ $default_root_response }};
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,6 +435,11 @@ server {
|
|||||||
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
{{ $upstream := printf "%s-%s" $upstream_name $sum }}
|
||||||
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "Vhostroot" $vhost_root) }}
|
{{ template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "Vhostroot" $vhost_root) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if (not (contains $paths "/")) }}
|
||||||
|
location / {
|
||||||
|
return {{ $default_root_response }};
|
||||||
|
}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
test/test_virtual-path/test_custom_conf.py
Normal file
6
test/test_virtual-path/test_custom_conf.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_default_root_response(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://nginx-proxy.test/")
|
||||||
|
assert r.status_code == 418
|
||||||
|
|
24
test/test_virtual-path/test_custom_conf.yml
Normal file
24
test/test_virtual-path/test_custom_conf.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
web1:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "81"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: "81"
|
||||||
|
VIRTUAL_HOST: "nginx-proxy.test"
|
||||||
|
VIRTUAL_PATH: "/web1/"
|
||||||
|
|
||||||
|
web2:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "82"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: "82"
|
||||||
|
VIRTUAL_HOST: "nginx-proxy.test"
|
||||||
|
VIRTUAL_PATH: "/web2/"
|
||||||
|
sut:
|
||||||
|
image: nginxproxy/nginx-proxy:test
|
||||||
|
environment:
|
||||||
|
DEFAULT_ROOT: 418
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
|
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
Loading…
x
Reference in New Issue
Block a user