diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 3137a17..c8ca701 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -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 \ && mkdir -p '/etc/nginx/toplevel.conf.d' \ && 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 COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego diff --git a/Dockerfile.debian b/Dockerfile.debian index cc9545b..08c014e 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -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 \ && mkdir -p '/etc/nginx/toplevel.conf.d' \ && 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 COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego diff --git a/docs/README.md b/docs/README.md index 949c0e8..5e79a02 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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. +### 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) ## TCP and UDP stream diff --git a/nginx.tmpl b/nginx.tmpl index 2ad4339..86f001f 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -702,7 +702,17 @@ server { return 444; } {{- end }} - return 503; + + {{- 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; + } } {{- end }} {{- end }} diff --git a/test/test_custom-error-page/50x.html b/test/test_custom-error-page/50x.html new file mode 100644 index 0000000..63a299e --- /dev/null +++ b/test/test_custom-error-page/50x.html @@ -0,0 +1,23 @@ + + + + Maintenance + + + +

Damn, there's some maintenance in progress.

+

+ Our apologies for this temporary inconvenience. Regular service + performance will be re-established shortly. +

+ + diff --git a/test/test_custom-error-page/test_custom-error-page.py b/test/test_custom-error-page/test_custom-error-page.py new file mode 100644 index 0000000..32cb0b5 --- /dev/null +++ b/test/test_custom-error-page/test_custom-error-page.py @@ -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) diff --git a/test/test_custom-error-page/test_custom-error-page.yml b/test/test_custom-error-page/test_custom-error-page.yml new file mode 100644 index 0000000..419b7eb --- /dev/null +++ b/test/test_custom-error-page/test_custom-error-page.yml @@ -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