Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to define a custom status code for forbidden locations #118

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: allow to define a custom status code for forbidden locations
Monska85 committed Jun 18, 2024

Verified

This commit was signed with the committer’s verified signature.
Monska85 Daniele Monti
commit 2ad53d58d771935d5e4f1fc78e325b62d31c0f02
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -104,6 +104,7 @@ The entrypoint file contains a list of environment variables that will be replac
- `NGINX_CLIENT_MAX_BODY_SIZE`: the maximum allowed size for the client request body (default: `200M`)
- `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`)
- `NGINX_CORS_DOMAINS`: a list of CORS enabled domains to activate cors just for the specified ones (no default provided)
- `NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE`: a valid return code used as return value when the forbidden locations are hitted (default `200`)

## Rootless feature

6 changes: 5 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -73,9 +73,13 @@ if [ -n "${NGINX_BASIC_AUTH_USER}" ] && [ -n "${NGINX_BASIC_AUTH_PASS}" ]; then
fi

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

# Activate HSTS header (default: off)
4 changes: 2 additions & 2 deletions templates/fragments/005-forbidden-locations.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
location = /core/install.php {
return 404;
return ${NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE};
}

location = /update.php {
return 404;
return ${NGINX_FORBIDDEN_LOCATIONS_EXIT_CODE};
}