Skip to content

Commit f92faae

Browse files
authored
Merge pull request #118 from sparkfabrik/feat/allow_custom_return_code_for_forbidden_locations
feat: allow to define a custom status code for forbidden locations
2 parents d410259 + 2ad53d5 commit f92faae

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ The entrypoint file contains a list of environment variables that will be replac
104104
- `NGINX_CLIENT_MAX_BODY_SIZE`: the maximum allowed size for the client request body (default: `200M`)
105105
- `NGINX_CORS_ENABLED`: enable cors for `/` path and the caller origin header represented by `$http_origin` nginx variable (<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin>) (default: `0`)
106106
- `NGINX_CORS_DOMAINS`: a list of CORS enabled domains to activate cors just for the specified ones (no default provided)
107+
- `NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE`: a valid return code used as return value when the forbidden locations are hitted (default `200`)
107108

108109
## Rootless feature
109110

docker-entrypoint.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ if [ -n "${NGINX_BASIC_AUTH_USER}" ] && [ -n "${NGINX_BASIC_AUTH_PASS}" ]; then
7373
fi
7474

7575
# Activate the forbidden locations when the environment is not local
76+
NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE=${NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE:-"200"}
77+
export NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE
7678
if [ "${ENV:-}" != "loc" ]; then
7779
print "Activating the forbidden locations"
78-
cp /templates/fragments/005-forbidden-locations.conf /etc/nginx/conf.d/fragments/005-forbidden-locations.conf
80+
# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
81+
envsubst '${NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE}' < /templates/fragments/005-forbidden-locations.conf > /etc/nginx/conf.d/fragments/005-forbidden-locations.conf
82+
cat /etc/nginx/conf.d/fragments/005-forbidden-locations.conf
7983
fi
8084

8185
# Activate HSTS header (default: off)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
location = /core/install.php {
2-
return 404;
2+
return ${NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE};
33
}
44

55
location = /update.php {
6-
return 404;
6+
return ${NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE};
77
}

0 commit comments

Comments
 (0)