mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
feat: DEFAULT_ROOT=none
disables the default location /
block
This commit is contained in:
parent
d3ded293ac
commit
f8ae0a4b00
15
README.md
15
README.md
@ -152,10 +152,17 @@ The filename of the previous example would be `example.tld_8610f6c344b4096614eab
|
|||||||
|
|
||||||
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.
|
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 `DEFAULT_ROOT=418` will return a 418 error page instead of the normal 404 one.
|
Exception: If this is set to the string `none`, no default `location /` directive will be generated. This makes it possible for you to provide your own `location /` directive in your [`/etc/nginx/vhost.d/VIRTUAL_HOST`](#per-virtual_host) or [`/etc/nginx/vhost.d/default`](#per-virtual_host-default-configuration) files.
|
||||||
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.
|
|
||||||
Nginx variables such as $scheme, $host, and $request_uri can be used. However, care must be taken to make sure the $ signs are escaped properly.
|
If unspecified, `DEFAULT_ROOT` defaults to `404`.
|
||||||
If you want to use `301 $scheme://$host/myapp1$request_uri` you should use:
|
|
||||||
|
Examples (YAML syntax):
|
||||||
|
|
||||||
|
* `DEFAULT_ROOT: "none"` prevents `nginx-proxy` from generating a default `location /` directive.
|
||||||
|
* `DEFAULT_ROOT: "418"` returns a 418 error page instead of the normal 404 one.
|
||||||
|
* `DEFAULT_ROOT: "301 https://github.com/nginx-proxy/nginx-proxy/blob/main/README.md"` redirects the client to this documentation.
|
||||||
|
|
||||||
|
Nginx variables such as `$scheme`, `$host`, and `$request_uri` can be used. However, care must be taken to make sure the `$` signs are escaped properly. For example, if you want to use `301 $scheme://$host/myapp1$request_uri` you should use:
|
||||||
|
|
||||||
* Bash: `DEFAULT_ROOT='301 $scheme://$host/myapp1$request_uri'`
|
* Bash: `DEFAULT_ROOT='301 $scheme://$host/myapp1$request_uri'`
|
||||||
* Docker Compose yaml: `- DEFAULT_ROOT: 301 $$scheme://$$host/myapp1$$request_uri`
|
* Docker Compose yaml: `- DEFAULT_ROOT: 301 $$scheme://$$host/myapp1$$request_uri`
|
||||||
|
@ -448,7 +448,7 @@ server {
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
|
{{- template "location" (dict "Path" $path "Proto" $proto "Upstream" $upstream "Host" $host "VhostRoot" $vhost_root "Dest" $dest "NetworkTag" $network_tag) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if (not (contains $paths "/")) }}
|
{{- if and (not (contains $paths "/")) (ne $globals.default_root_response "none")}}
|
||||||
location / {
|
location / {
|
||||||
return {{ $globals.default_root_response }};
|
return {{ $globals.default_root_response }};
|
||||||
}
|
}
|
||||||
|
8
test/test_default-root-none.py
Normal file
8
test/test_default-root-none.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_root_none(docker_compose, nginxproxy):
|
||||||
|
conf = nginxproxy.get_conf().decode()
|
||||||
|
assert re.search(r"(?m)^\s*location\s+/path\s+\{", conf)
|
||||||
|
assert not re.search(r"(?m)^\s*location\s+/\s+\{", conf)
|
||||||
|
|
15
test/test_default-root-none.yml
Normal file
15
test/test_default-root-none.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
services:
|
||||||
|
sut:
|
||||||
|
image: nginxproxy/nginx-proxy:test
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
|
environment:
|
||||||
|
DEFAULT_ROOT: none
|
||||||
|
web:
|
||||||
|
image: web
|
||||||
|
expose:
|
||||||
|
- "80"
|
||||||
|
environment:
|
||||||
|
WEB_PORTS: "80"
|
||||||
|
VIRTUAL_HOST: web.nginx-proxy.test
|
||||||
|
VIRTUAL_PATH: /path
|
Loading…
x
Reference in New Issue
Block a user