feat: Add server names hash tuning options to nginx configuration

This commit is contained in:
Simon Larsen
2025-08-12 17:39:47 +01:00
parent 51d42c8436
commit 26cfbd07cb
4 changed files with 31 additions and 1 deletions

View File

@@ -111,6 +111,14 @@ spec:
value: {{ $.Values.nginx.listenAddress | quote }}
- name: NGINX_LISTEN_OPTIONS
value: {{ $.Values.nginx.listenOptions | quote }}
{{- if $.Values.nginx.serverNamesHash.bucketSize }}
- name: SERVER_NAMES_HASH_BUCKET_SIZE
value: {{ $.Values.nginx.serverNamesHash.bucketSize | quote }}
{{- end }}
{{- if $.Values.nginx.serverNamesHash.maxSize }}
- name: SERVER_NAMES_HASH_MAX_SIZE
value: {{ $.Values.nginx.serverNamesHash.maxSize | quote }}
{{- end }}
- name: ONEUPTIME_HTTP_PORT
value: {{ $.Values.nginx.ports.http | quote }}
- name: PORT

View File

@@ -43,6 +43,9 @@ nginx:
disableAutoscaler: false
listenAddress: ""
listenOptions: ""
serverNamesHash:
bucketSize: ""
maxSize: ""
ports:
http: 80
https: 443

View File

@@ -1,3 +1,8 @@
## Hash tuning for many/long server names. Can be overridden via env vars.
## Defaults are provided by envsubst-on-templates.sh if not set.
server_names_hash_bucket_size ${SERVER_NAMES_HASH_BUCKET_SIZE};
server_names_hash_max_size ${SERVER_NAMES_HASH_MAX_SIZE};
upstream accounts {
server ${SERVER_ACCOUNTS_HOSTNAME}:${ACCOUNTS_PORT} weight=10 max_fails=3 fail_timeout=30s;
}

View File

@@ -25,8 +25,22 @@ auto_envsubst() {
subdir=$(dirname "$relative_path")
# create a subdirectory where the template file exists
mkdir -p "$output_dir/$subdir"
# Make a temp copy to allow conditional line removal
tmpfile=$(mktemp)
cp "$template" "$tmpfile"
# If hash tuning envs are not set, remove their lines from the template
if [ -z "${SERVER_NAMES_HASH_BUCKET_SIZE}" ]; then
sed -i '/^[[:space:]]*server_names_hash_bucket_size[[:space:]]/d' "$tmpfile"
fi
if [ -z "${SERVER_NAMES_HASH_MAX_SIZE}" ]; then
sed -i '/^[[:space:]]*server_names_hash_max_size[[:space:]]/d' "$tmpfile"
fi
echo "$ME: Running envsubst on $template to $output_path"
envsubst "$defined_envs" < "$template" > "$output_path"
envsubst "$defined_envs" < "$tmpfile" > "$output_path"
rm -f "$tmpfile"
done
}