From 3a385fc08d4a48da1f2ae5bca3ab59b605174ba8 Mon Sep 17 00:00:00 2001 From: Joxit Date: Mon, 8 Nov 2021 05:28:39 +0100 Subject: [PATCH] feat(nginx): add support for `proxy_pass_header` directive via `NGINX_PROXY_PASS_HEADER_*` fixes #206 --- README.md | 6 ++++-- bin/entrypoint | 17 +++++++++++++++++ nginx/default.conf | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a14a284..8f95bdd7 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,8 @@ This web user interface uses [Riot](https://github.com/Riot/riot) the react-like - Multi arch support in history page (see [#130](https://github.com/Joxit/docker-registry-ui/issues/130) and [#134](https://github.com/Joxit/docker-registry-ui/pull/134)) - Set a list of default registries with `DEFAULT_REGISTRIES` (see [#219](https://github.com/Joxit/docker-registry-ui/pull/219)). - Desactivate add and remove regisitries with `READ_ONLY_REGISTRIES` (see [#219](https://github.com/Joxit/docker-registry-ui/pull/219)). -- Filter images and tags with a search bar. You can select the search bar with the shortcut `CRTL` + `F` or `F3`. When the search bar is already focused, the shortcut will fallback to the default behavior (see [#213](https://github.com/Joxit/docker-registry-ui/issues/213)). +- Filter images and tags with a search bar. You can select the search bar with the shortcut `CRTL` + `F` or `F3`. When the search bar is already focused, the shortcut will fallback to the default behavior (see [#213](https://github.com/Joxit/docker-registry-ui/issues/213)). +- **Forward** custom header to your backend registry via environment variable and file via `NGINX_PROXY_PASS_HEADER_*` (see [#206](https://github.com/Joxit/docker-registry-ui/pull/206)). ## FAQ @@ -90,7 +91,8 @@ Some env options are available for use this interface for **only one server**. - `CATALOG_ELEMENTS_LIMIT`: Limit the number of elements in the catalog page. (default: `100000`). - `SINGLE_REGISTRY`: Remove the menu that show the dialogs to add, remove and change the endpoint of your docker registry. (default: `false`). - `NGINX_PROXY_PASS_URL`: Update the default Nginx configuration and set the **proxy_pass** to your backend docker registry (this avoid CORS configuration). This is usually the name of your registry container in the form `http://registry:5000`. -- `NGINX_PROXY_HEADER_*`: Update the default Nginx configuration and set **custom headers** for your backend docker registry. Only when `NGINX_PROXY_PASS_URL` is used. +- `NGINX_PROXY_HEADER_*`: Update the default Nginx configuration and **set custom headers** for your backend docker registry. Only when `NGINX_PROXY_PASS_URL` is used. +- `NGINX_PROXY_HEADER_*`: Update the default Nginx configuration and **forward custom headers** to your backend docker registry. Only when `NGINX_PROXY_PASS_URL` is used. - `DEFAULT_REGISTRIES`: List of comma separated registry URLs (e.g `http://registry.example.com,http://registry:5000`), available only when `SINGLE_REGISTRY=false`. (default: ` `). - `READ_ONLY_REGISTRIES`: Desactivate dialog for remove and add new registries, available only when `SINGLE_REGISTRY=false`. (default: `false`). diff --git a/bin/entrypoint b/bin/entrypoint index 1cb40e5a..15218b11 100755 --- a/bin/entrypoint +++ b/bin/entrypoint @@ -32,8 +32,25 @@ get_nginx_proxy_headers() { done } +get_nginx_proxy_pass_headers() { + ( + env && + if [ -f "/etc/nginx/.env" ]; then + cat /etc/nginx/.env + # Force new line + echo "" + fi + ) | while read e; do + if [ -n "$(echo $e | grep -o '^NGINX_PROXY_PASS_HEADER_')" ]; then + key=$(echo ${e%%=*} | sed 's/^NGINX_PROXY_PASS_HEADER_//' | sed 's/_/-/g') + echo -n "proxy_pass_header \"${key}\"; " + fi + done +} + if [ -n "${NGINX_PROXY_PASS_URL}" ] ; then sed -i "s,\${NGINX_PROXY_PASS_URL},${NGINX_PROXY_PASS_URL}," /etc/nginx/conf.d/default.conf sed -i "s^\${NGINX_PROXY_HEADERS}^$(get_nginx_proxy_headers)^" /etc/nginx/conf.d/default.conf + sed -i "s^\${NGINX_PROXY_PASS_HEADERS}^$(get_nginx_proxy_pass_headers)^" /etc/nginx/conf.d/default.conf sed -i "s,#!,," /etc/nginx/conf.d/default.conf fi diff --git a/nginx/default.conf b/nginx/default.conf index 3f7bf0c9..c6a8e39f 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -27,6 +27,7 @@ server { #! return 404; #! } #! ${NGINX_PROXY_HEADERS} +#! ${NGINX_PROXY_PASS_HEADERS} #! proxy_pass ${NGINX_PROXY_PASS_URL}; #! }