Skip to content

Commit 4583be4

Browse files
authored
Merge pull request #78 from wwwehr/npw/boost-header-proxy-size
custom domain nginx reverse proxy header size
2 parents 386a2e9 + ca966b0 commit 4583be4

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

custom-domain/dstack-ingress/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ configs:
180180
- `PROXY_READ_TIMEOUT`: Optional value for nginx `proxy_read_timeout` (numeric with optional `s|m|h` suffix, e.g. `30s`) in single-domain mode
181181
- `PROXY_SEND_TIMEOUT`: Optional value for nginx `proxy_send_timeout` (numeric with optional `s|m|h` suffix, e.g. `30s`) in single-domain mode
182182
- `PROXY_CONNECT_TIMEOUT`: Optional value for nginx `proxy_connect_timeout` (numeric with optional `s|m|h` suffix, e.g. `10s`) in single-domain mode
183+
- `PROXY_BUFFER_SIZE`: Optional value for nginx `proxy_buffer_size` (numeric with optional `k|m` suffix, e.g. `128k`) in single-domain mode
184+
- `PROXY_BUFFERS`: Optional value for nginx `proxy_buffers` (format: `number size`, e.g. `4 256k`) in single-domain mode
185+
- `PROXY_BUSY_BUFFERS_SIZE`: Optional value for nginx `proxy_busy_buffers_size` (numeric with optional `k|m` suffix, e.g. `256k`) in single-domain mode
183186
- `CERTBOT_STAGING`: Optional; set this value to the string `true` to set the `--staging` server option on the [`certbot` cli](https://eff-certbot.readthedocs.io/en/stable/using.html#certbot-command-line-options)
184187

185188
**Backward Compatibility:**

custom-domain/dstack-ingress/scripts/entrypoint.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ fi
2828
if ! PROXY_CONNECT_TIMEOUT=$(sanitize_proxy_timeout "$PROXY_CONNECT_TIMEOUT"); then
2929
exit 1
3030
fi
31+
if ! PROXY_BUFFER_SIZE=$(sanitize_proxy_buffer_size "$PROXY_BUFFER_SIZE"); then
32+
exit 1
33+
fi
34+
if ! PROXY_BUFFERS=$(sanitize_proxy_buffers "$PROXY_BUFFERS"); then
35+
exit 1
36+
fi
37+
if ! PROXY_BUSY_BUFFERS_SIZE=$(sanitize_proxy_buffer_size "$PROXY_BUSY_BUFFERS_SIZE"); then
38+
exit 1
39+
fi
3140
if ! TXT_PREFIX=$(sanitize_dns_label "$TXT_PREFIX"); then
3241
exit 1
3342
fi
@@ -117,6 +126,21 @@ setup_nginx_conf() {
117126
proxy_connect_timeout_conf=" ${PROXY_CMD}_connect_timeout ${PROXY_CONNECT_TIMEOUT};"
118127
fi
119128

129+
local proxy_buffer_size_conf=""
130+
if [ -n "$PROXY_BUFFER_SIZE" ]; then
131+
proxy_buffer_size_conf=" proxy_buffer_size ${PROXY_BUFFER_SIZE};"
132+
fi
133+
134+
local proxy_buffers_conf=""
135+
if [ -n "$PROXY_BUFFERS" ]; then
136+
proxy_buffers_conf=" proxy_buffers ${PROXY_BUFFERS};"
137+
fi
138+
139+
local proxy_busy_buffers_size_conf=""
140+
if [ -n "$PROXY_BUSY_BUFFERS_SIZE" ]; then
141+
proxy_busy_buffers_size_conf=" proxy_busy_buffers_size ${PROXY_BUSY_BUFFERS_SIZE};"
142+
fi
143+
120144
cat <<EOF >/etc/nginx/conf.d/default.conf
121145
server {
122146
listen ${PORT} ssl;
@@ -153,6 +177,9 @@ server {
153177
154178
# SSL buffer size (optimized for TLS 1.3)
155179
ssl_buffer_size 4k;
180+
${proxy_buffer_size_conf}
181+
${proxy_buffers_conf}
182+
${proxy_busy_buffers_size_conf}
156183
157184
# Disable SSL renegotiation
158185
ssl_early_data off;

custom-domain/dstack-ingress/scripts/functions.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,35 @@ sanitize_proxy_timeout() {
8383
fi
8484
}
8585

86+
sanitize_proxy_buffer_size() {
87+
local candidate="$1"
88+
if [ -z "$candidate" ]; then
89+
echo ""
90+
return 0
91+
fi
92+
if [[ "$candidate" =~ ^[0-9]+[kKmM]?$ ]]; then
93+
echo "$candidate"
94+
else
95+
echo "Warning: Ignoring invalid proxy buffer size value: $candidate" >&2
96+
echo ""
97+
fi
98+
}
99+
100+
sanitize_proxy_buffers() {
101+
local candidate="$1"
102+
if [ -z "$candidate" ]; then
103+
echo ""
104+
return 0
105+
fi
106+
# Format: number size (e.g., "4 256k")
107+
if [[ "$candidate" =~ ^[0-9]+[[:space:]]+[0-9]+[kKmM]?$ ]]; then
108+
echo "$candidate"
109+
else
110+
echo "Warning: Ignoring invalid proxy buffers value: $candidate (expected format: 'number size', e.g., '4 256k')" >&2
111+
echo ""
112+
fi
113+
}
114+
86115
get_letsencrypt_account_path() {
87116
local base_path="/etc/letsencrypt/accounts"
88117
local api_endpoint="acme-v02.api.letsencrypt.org"

0 commit comments

Comments
 (0)