Render the header inside location / so it is not dropped by other location headers; remove the ineffective server-level directive.
44 lines
1.2 KiB
Bash
44 lines
1.2 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
max_image_bytes="${VALIDATION_UPLOAD_MAX_IMAGE_BYTES:?}"
|
|
json_padding="${VALIDATION_UPLOAD_JSON_BODY_PADDING_BYTES:?}"
|
|
|
|
UPLOAD_MAX_REQUEST_BODY_BYTES=$(( (max_image_bytes * 4 + 2) / 3 + json_padding ))
|
|
|
|
export UPLOAD_MAX_REQUEST_BODY_BYTES BACKEND_PORT
|
|
|
|
render_locations() {
|
|
export ONION_LOCATION_HEADER="add_header Onion-Location \"http://${ONION_HOSTNAME}\$request_uri\" always;"
|
|
|
|
envsubst '${BACKEND_PORT} ${UPLOAD_MAX_REQUEST_BODY_BYTES} ${ONION_LOCATION_HEADER}' \
|
|
< /etc/nginx/templates/snippets/private-image-locations.conf.template \
|
|
> /etc/nginx/snippets/private-image-locations.conf
|
|
}
|
|
|
|
render_server() {
|
|
template_path="$1"
|
|
output_path="$2"
|
|
surface="$3"
|
|
|
|
if [ "$surface" = "clearnet" ]; then
|
|
export CLEARNET_DOMAIN
|
|
|
|
envsubst '${CLEARNET_DOMAIN}' \
|
|
< "$template_path" \
|
|
> "$output_path"
|
|
|
|
return
|
|
fi
|
|
|
|
cp "$template_path" "$output_path"
|
|
}
|
|
|
|
mkdir -p /etc/nginx/snippets
|
|
|
|
render_locations
|
|
render_server /etc/nginx/templates/conf.d/clearnet.conf.template /etc/nginx/conf.d/clearnet.conf clearnet
|
|
render_server /etc/nginx/templates/conf.d/onion.conf.template /etc/nginx/conf.d/onion.conf onion
|
|
|
|
exec nginx -g 'daemon off;'
|