mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
feat: custom default error page (#2430)
* feat: customizable error page * fix: use regex on catchall root location to fix DEFAULT_ROOT=none test * docs: custom error pages * fix: don't use default nginx image error page * docs: small fix
This commit is contained in:
parent
b4c7ea603e
commit
fb9c3a646a
@ -22,7 +22,8 @@ RUN echo -e "\ninclude /etc/nginx/toplevel.conf.d/*.conf;" >> /etc/nginx/nginx.c
|
|||||||
&& sed -i -e '/^\}$/{s//\}\nworker_rlimit_nofile 20480;/;:a' -e '$!N;$!ba' -e '}' /etc/nginx/nginx.conf \
|
&& sed -i -e '/^\}$/{s//\}\nworker_rlimit_nofile 20480;/;:a' -e '$!N;$!ba' -e '}' /etc/nginx/nginx.conf \
|
||||||
&& mkdir -p '/etc/nginx/toplevel.conf.d' \
|
&& mkdir -p '/etc/nginx/toplevel.conf.d' \
|
||||||
&& mkdir -p '/etc/nginx/dhparam' \
|
&& mkdir -p '/etc/nginx/dhparam' \
|
||||||
&& mkdir -p '/etc/nginx/certs'
|
&& mkdir -p '/etc/nginx/certs' \
|
||||||
|
&& mkdir -p '/usr/share/nginx/html/errors'
|
||||||
|
|
||||||
# Install Forego + docker-gen
|
# Install Forego + docker-gen
|
||||||
COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego
|
COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego
|
||||||
|
@ -19,7 +19,8 @@ RUN echo "\ninclude /etc/nginx/toplevel.conf.d/*.conf;" >> /etc/nginx/nginx.conf
|
|||||||
&& sed -i -e '/^\}$/{s//\}\nworker_rlimit_nofile 20480;/;:a' -e '$!N;$!ba' -e '}' /etc/nginx/nginx.conf \
|
&& sed -i -e '/^\}$/{s//\}\nworker_rlimit_nofile 20480;/;:a' -e '$!N;$!ba' -e '}' /etc/nginx/nginx.conf \
|
||||||
&& mkdir -p '/etc/nginx/toplevel.conf.d' \
|
&& mkdir -p '/etc/nginx/toplevel.conf.d' \
|
||||||
&& mkdir -p '/etc/nginx/dhparam' \
|
&& mkdir -p '/etc/nginx/dhparam' \
|
||||||
&& mkdir -p '/etc/nginx/certs'
|
&& mkdir -p '/etc/nginx/certs' \
|
||||||
|
&& mkdir -p '/usr/share/nginx/html/errors'
|
||||||
|
|
||||||
# Install Forego + docker-gen
|
# Install Forego + docker-gen
|
||||||
COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego
|
COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego
|
||||||
|
@ -797,6 +797,21 @@ location / {
|
|||||||
|
|
||||||
Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details.
|
Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details.
|
||||||
|
|
||||||
|
### Custom error page
|
||||||
|
|
||||||
|
To override the default error page displayed on 50x errors, mount your custom HTML error page inside the container at `/usr/share/nginx/html/errors/50x.html`:
|
||||||
|
|
||||||
|
```console
|
||||||
|
docker run --detach \
|
||||||
|
--name nginx-proxy \
|
||||||
|
--publish 80:80 \
|
||||||
|
--volume /var/run/docker.sock:/tmp/docker.sock:ro \
|
||||||
|
--volume /path/to/error.html:/usr/share/nginx/html/errors/50x.html:ro \
|
||||||
|
nginxproxy/nginx-proxy:1.5
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that this will not replace your own services error pages.
|
||||||
|
|
||||||
⬆️ [back to table of contents](#table-of-contents)
|
⬆️ [back to table of contents](#table-of-contents)
|
||||||
|
|
||||||
## TCP and UDP stream
|
## TCP and UDP stream
|
||||||
|
10
nginx.tmpl
10
nginx.tmpl
@ -702,8 +702,18 @@ server {
|
|||||||
return 444;
|
return 444;
|
||||||
}
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
{{- if (exists "/usr/share/nginx/html/errors/50x.html") }}
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location /50x.html {
|
||||||
|
root /usr/share/nginx/html/errors;
|
||||||
|
internal;
|
||||||
|
}
|
||||||
|
{{- end }}
|
||||||
|
location ^~ / {
|
||||||
return 503;
|
return 503;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
23
test/test_custom-error-page/50x.html
Normal file
23
test/test_custom-error-page/50x.html
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Maintenance</title>
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
color-scheme: light dark;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
width: 35em;
|
||||||
|
margin: 0 auto;
|
||||||
|
font-family: Tahoma, Verdana, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Damn, there's some maintenance in progress.</h1>
|
||||||
|
<p>
|
||||||
|
Our apologies for this temporary inconvenience. Regular service
|
||||||
|
performance will be re-established shortly.
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
8
test/test_custom-error-page/test_custom-error-page.py
Normal file
8
test/test_custom-error-page/test_custom-error-page.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import pytest
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def test_custom_error_page(docker_compose, nginxproxy):
|
||||||
|
r = nginxproxy.get("http://unknown.nginx-proxy.tld")
|
||||||
|
assert r.status_code == 503
|
||||||
|
assert re.search(r"Damn, there's some maintenance in progress.", r.text)
|
8
test/test_custom-error-page/test_custom-error-page.yml
Normal file
8
test/test_custom-error-page/test_custom-error-page.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: "2"
|
||||||
|
|
||||||
|
services:
|
||||||
|
sut:
|
||||||
|
image: nginxproxy/nginx-proxy:test
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
|
- ./50x.html:/usr/share/nginx/html/errors/50x.html:ro
|
Loading…
x
Reference in New Issue
Block a user