Make nginx-proxy-http-version configurable per app or globally

This commit is contained in:
Schlepptop
2026-10-19 00:44:59 +02:00
parent 8d696d1207
commit 4badd065cc
10 changed files with 102 additions and 43 deletions

View File

@@ -455,6 +455,8 @@ Changing these value globally or on a per-app basis will require rebuilding the
| proxy-buffering | `on` | string | Enables or disables buffering of responses from the proxied server |
| proxy-buffers | `8 8k` | string | Number and size of the buffers used for reading the proxied server response, for a single connection |
| proxy-busy-buffers-size | `16k` | string | Limits the total size of buffers that can be busy sending a response to the client while the response is not yet fully read. |
| proxy-http-version | `1.1` | string | The HTTP version to use for establishing a connection to your backend server. Ensure that your backend server supports this. |
| proxy-connect-timeout | `60s` | string | Timeout (with units) for establishing a connection to your backend server |
| proxy-keepalive | empty (disabled) | integer | Number of idle keepalive connections to upstream servers (disabled by default) |
| proxy-read-timeout | `60s` | string | Timeout (with units) for reading response from your backend server |
@@ -654,6 +656,7 @@ All nginx-vhosts properties are settable at both the app and global scope.
| `proxy-buffering` | app + global | `on` | `--nginx-proxy-buffering`, `--nginx-global-proxy-buffering`, `--nginx-computed-proxy-buffering` | Whether nginx buffers upstream responses (`on` or `off`) |
| `proxy-buffers` | app + global | _`8 {pagesize}`_ | `--nginx-proxy-buffers`, `--nginx-global-proxy-buffers`, `--nginx-computed-proxy-buffers` | Number and size of buffers used for an upstream response |
| `proxy-busy-buffers-size` | app + global | _`2 * pagesize`_ | `--nginx-proxy-busy-buffers-size`, `--nginx-global-proxy-busy-buffers-size`, `--nginx-computed-proxy-busy-buffers-size` | Maximum buffer size that can be busy sending a response to the client |
| `proxy-http-version` | app + global | `1.1` | `--nginx-proxy-http-version`, `--nginx-global-proxy-http-version`, `--nginx-computed-proxy-http-version` | HTTP version to use for a connection to the upstream |
| `proxy-connect-timeout` | app + global | `60s` | `--nginx-proxy-connect-timeout`, `--nginx-global-proxy-connect-timeout`, `--nginx-computed-proxy-connect-timeout` | Time to establish a connection to the upstream |
| `proxy-keepalive` | app + global | none | `--nginx-proxy-keepalive`, `--nginx-global-proxy-keepalive`, `--nginx-computed-proxy-keepalive` | Number of idle keep-alive connections to upstream servers held open per worker |
| `proxy-read-timeout` | app + global | `60s` | `--nginx-proxy-read-timeout`, `--nginx-global-proxy-read-timeout`, `--nginx-computed-proxy-read-timeout` | Time to read a response from the upstream |

View File

@@ -282,6 +282,7 @@ fn-nginx-vhosts-render-template() {
local CLIENT_MAX_BODY_SIZE="$(fn-nginx-computed-client-max-body-size "$APP")"
local KEEPALIVE_TIMEOUT="$(fn-nginx-computed-keepalive-timeout "$APP")"
local LINGERING_TIMEOUT="$(fn-nginx-computed-lingering-timeout "$APP")"
local PROXY_HTTP_VERSION="$(fn-nginx-computed-proxy-http-version "$APP")"
local PROXY_CONNECT_TIMEOUT="$(fn-nginx-computed-proxy-connect-timeout "$APP")"
local PROXY_READ_TIMEOUT="$(fn-nginx-computed-proxy-read-timeout "$APP")"
local PROXY_SEND_TIMEOUT="$(fn-nginx-computed-proxy-send-timeout "$APP")"
@@ -334,6 +335,7 @@ fn-nginx-vhosts-render-template() {
CLIENT_MAX_BODY_SIZE="$CLIENT_MAX_BODY_SIZE"
KEEPALIVE_TIMEOUT="$KEEPALIVE_TIMEOUT"
LINGERING_TIMEOUT="$LINGERING_TIMEOUT"
PROXY_HTTP_VERSION="$PROXY_HTTP_VERSION"
PROXY_CONNECT_TIMEOUT="$PROXY_CONNECT_TIMEOUT"
PROXY_READ_TIMEOUT="$PROXY_READ_TIMEOUT"
PROXY_SEND_TIMEOUT="$PROXY_SEND_TIMEOUT"

View File

@@ -425,6 +425,27 @@ fn-nginx-global-proxy-busy-buffers-size() {
fn-get-property --app "$APP" --global "proxy-busy-buffers-size"
}
fn-nginx-proxy-http-version() {
declare desc="get the configured proxy http version"
declare APP="$1"
fn-get-property --app "$APP" "proxy-http-version"
}
fn-nginx-computed-proxy-http-version() {
declare desc="get the computed proxy http version"
declare APP="$1"
fn-get-property --app "$APP" --computed "proxy-http-version"
}
fn-nginx-global-proxy-connect-timeout() {
declare desc="get the global proxy http version"
declare APP="$1"
fn-get-property --app "$APP" --global "proxy-http-version"
}
fn-nginx-proxy-connect-timeout() {
declare desc="get the configured proxy connect timeout"
declare APP="$1"

View File

@@ -436,6 +436,27 @@ func GlobalProxyBusyBuffersSize() string {
return common.PropertyGet("nginx", "--global", "proxy-busy-buffers-size")
}
func AppProxyHttpVersion(appName string) string {
return common.PropertyGet("nginx", appName, "proxy-http-version")
}
func ComputedProxyHttpVersion(appName string) string {
appValue := AppProxyHttpVersion(appName)
if appValue != "" {
return appValue
}
value := GlobalProxyHttpVersion()
if value == "" {
value = "1.1"
}
return value
}
func GlobalProxyHttpVersion() string {
return common.PropertyGet("nginx", "--global", "proxy-connect-timeout")
}
func AppProxyConnectTimeout(appName string) string {
return common.PropertyGet("nginx", appName, "proxy-connect-timeout")
}

View File

@@ -77,6 +77,8 @@ func appValue(appName string, property string) string {
value = nginx_vhosts.AppProxyBuffers(appName)
case "proxy-busy-buffers-size":
value = nginx_vhosts.AppProxyBusyBuffersSize(appName)
case "proxy-http-version":
value = nginx_vhosts.AppProxyHttpVersion(appName)
case "proxy-connect-timeout":
value = nginx_vhosts.AppProxyConnectTimeout(appName)
case "proxy-read-timeout":
@@ -147,6 +149,8 @@ func computedValue(appName string, property string) string {
value = nginx_vhosts.ComputedProxyBuffers(appName)
case "proxy-busy-buffers-size":
value = nginx_vhosts.ComputedProxyBusyBuffersSize(appName)
case "proxy-http-version":
value = nginx_vhosts.ComputedProxyHttpVersion(appName)
case "proxy-connect-timeout":
value = nginx_vhosts.ComputedProxyConnectTimeout(appName)
case "proxy-read-timeout":
@@ -217,6 +221,8 @@ func globalValue(appName string, property string) string {
value = nginx_vhosts.GlobalProxyBuffers()
case "proxy-busy-buffers-size":
value = nginx_vhosts.GlobalProxyBusyBuffersSize()
case "proxy-http-version":
value = nginx_vhosts.GlobalProxyHttpVersion()
case "proxy-connect-timeout":
value = nginx_vhosts.GlobalProxyConnectTimeout()
case "proxy-read-timeout":

View File

@@ -9,13 +9,13 @@ cmd-nginx-set() {
declare cmd="nginx:set"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" KEY="$2" VALUE="$3"
local VALID_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "nginx-service-command" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "proxy-keepalive" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
local GLOBAL_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts-include-subdomains" "hsts-max-age" "hsts-preload" "hsts" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "nginx-service-command" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "proxy-keepalive" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
local VALID_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "nginx-service-command" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-http-version" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "proxy-keepalive" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
local GLOBAL_KEYS=("access-log-format" "access-log-path" "bind-address-ipv4" "bind-address-ipv6" "client-body-timeout" "client-header-timeout" "client-max-body-size" "disable-custom-config" "error-log-path" "hsts-include-subdomains" "hsts-max-age" "hsts-preload" "hsts" "keepalive-timeout" "lingering-timeout" "nginx-conf-sigil-path" "nginx-service-command" "proxy-buffer-size" "proxy-buffering" "proxy-buffers" "proxy-busy-buffers-size" "proxy-http-version" "proxy-connect-timeout" "proxy-read-timeout" "proxy-send-timeout" "proxy-keepalive" "send-timeout" "underscore-in-headers" "x-forwarded-for-value" "x-forwarded-port-value" "x-forwarded-proto-value" "x-forwarded-ssl")
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
dokku_log_fail "Invalid key specified, valid keys include: access-log-format, access-log-path, bind-address-ipv4, bind-address-ipv6, client-body-timeout, client-header-timeout, client-max-body-size, disable-custom-config, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, keepalive-timeout, lingering-timeout, nginx-conf-sigil-path, nginx-service-command, proxy-buffer-size, proxy-buffering, proxy-buffers, proxy-busy-buffers-size, proxy-connect-timeout, proxy-read-timeout, proxy-send-timeout, proxy-keepalive, send-timeout, underscore-in-headers, x-forwarded-for-value, x-forwarded-port-value, x-forwarded-proto-value, x-forwarded-ssl"
dokku_log_fail "Invalid key specified, valid keys include: access-log-format, access-log-path, bind-address-ipv4, bind-address-ipv6, client-body-timeout, client-header-timeout, client-max-body-size, disable-custom-config, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, keepalive-timeout, lingering-timeout, nginx-conf-sigil-path, nginx-service-command, proxy-buffer-size, proxy-buffering, proxy-buffers, proxy-busy-buffers-size, proxy-http-version, proxy-connect-timeout, proxy-read-timeout, proxy-send-timeout, proxy-keepalive, send-timeout, underscore-in-headers, x-forwarded-for-value, x-forwarded-port-value, x-forwarded-proto-value, x-forwarded-ssl"
fi
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}" && [[ "$APP" == "--global" ]]; then

View File

@@ -22,43 +22,44 @@ func templatePath(t *testing.T) string {
func defaultVars() map[string]interface{} {
return map[string]interface{}{
"APP": "app",
"DOKKU_ROOT": "/home/dokku",
"DOKKU_LIB_ROOT": "/var/lib/dokku",
"NOSSL_SERVER_NAME": "app.example.com",
"SSL_SERVER_NAME": "",
"SSL_INUSE": "",
"APP_SSL_PATH": "/home/dokku/app/tls",
"DOKKU_APP_WEB_LISTENERS": "127.0.0.1:5000",
"PROXY_PORT_MAP": "http:80:5000",
"PROXY_UPSTREAM_PORTS": "5000",
"PROXY_PORT": "80",
"PROXY_SSL_PORT": "443",
"PROXY_KEEPALIVE": "",
"NGINX_BIND_ADDRESS_IP4": "",
"NGINX_BIND_ADDRESS_IP6": "::",
"NGINX_ACCESS_LOG_PATH": "/var/log/nginx/app-access.log",
"NGINX_ACCESS_LOG_FORMAT": "",
"NGINX_ERROR_LOG_PATH": "/var/log/nginx/app-error.log",
"NGINX_UNDERSCORE_IN_HEADERS": "off",
"CLIENT_BODY_TIMEOUT": "60s",
"CLIENT_HEADER_TIMEOUT": "60s",
"CLIENT_MAX_BODY_SIZE": "1m",
"KEEPALIVE_TIMEOUT": "75s",
"LINGERING_TIMEOUT": "5s",
"SEND_TIMEOUT": "60s",
"PROXY_CONNECT_TIMEOUT": "60s",
"PROXY_READ_TIMEOUT": "60s",
"PROXY_SEND_TIMEOUT": "60s",
"PROXY_BUFFER_SIZE": "4k",
"PROXY_BUFFERING": "on",
"PROXY_BUFFERS": "8 4k",
"PROXY_BUSY_BUFFERS_SIZE": "8k",
"PROXY_X_FORWARDED_FOR": "$remote_addr",
"PROXY_X_FORWARDED_PORT": "$server_port",
"PROXY_X_FORWARDED_PROTO": "$scheme",
"PROXY_X_FORWARDED_SSL": "",
"HTTP2_DIRECTIVE_SUPPORTED": "true",
"APP": "app",
"DOKKU_ROOT": "/home/dokku",
"DOKKU_LIB_ROOT": "/var/lib/dokku",
"NOSSL_SERVER_NAME": "app.example.com",
"SSL_SERVER_NAME": "",
"SSL_INUSE": "",
"APP_SSL_PATH": "/home/dokku/app/tls",
"DOKKU_APP_WEB_LISTENERS": "127.0.0.1:5000",
"PROXY_PORT_MAP": "http:80:5000",
"PROXY_UPSTREAM_PORTS": "5000",
"PROXY_PORT": "80",
"PROXY_SSL_PORT": "443",
"PROXY_KEEPALIVE": "",
"NGINX_BIND_ADDRESS_IP4": "",
"NGINX_BIND_ADDRESS_IP6": "::",
"NGINX_ACCESS_LOG_PATH": "/var/log/nginx/app-access.log",
"NGINX_ACCESS_LOG_FORMAT": "",
"NGINX_ERROR_LOG_PATH": "/var/log/nginx/app-error.log",
"NGINX_UNDERSCORE_IN_HEADERS": "off",
"CLIENT_BODY_TIMEOUT": "60s",
"CLIENT_HEADER_TIMEOUT": "60s",
"CLIENT_MAX_BODY_SIZE": "1m",
"KEEPALIVE_TIMEOUT": "75s",
"LINGERING_TIMEOUT": "5s",
"SEND_TIMEOUT": "60s",
"PROXY_HTTP_VERSION": "1.1",
"PROXY_CONNECT_TIMEOUT": "60s",
"PROXY_READ_TIMEOUT": "60s",
"PROXY_SEND_TIMEOUT": "60s",
"PROXY_BUFFER_SIZE": "4k",
"PROXY_BUFFERING": "on",
"PROXY_BUFFERS": "8 4k",
"PROXY_BUSY_BUFFERS_SIZE": "8k",
"PROXY_X_FORWARDED_FOR": "$remote_addr",
"PROXY_X_FORWARDED_PORT": "$server_port",
"PROXY_X_FORWARDED_PROTO": "$scheme",
"PROXY_X_FORWARDED_SSL": "",
"HTTP2_DIRECTIVE_SUPPORTED": "true",
}
}
@@ -266,8 +267,8 @@ func TestTemplate_XForwardedSSL(t *testing.T) {
func TestTemplate_NginxConfDIncludeAlways(t *testing.T) {
cases := []struct {
name string
mutate func(map[string]interface{})
name string
mutate func(map[string]interface{})
}{
{"http", func(v map[string]interface{}) {}},
{"http_redirect", func(v map[string]interface{}) {

View File

@@ -58,7 +58,7 @@ server {
proxy_pass http://{{ $.APP }}-{{ $upstream_port }};
{{ if and $is_ssl (eq $.HTTP2_PUSH_SUPPORTED "true") }}http2_push_preload on; {{ end }}
proxy_http_version 1.1;
proxy_http_version {{ $.PROXY_HTTP_VERSION }};
proxy_connect_timeout {{ $.PROXY_CONNECT_TIMEOUT }};
proxy_read_timeout {{ $.PROXY_READ_TIMEOUT }};
proxy_send_timeout {{ $.PROXY_SEND_TIMEOUT }};

View File

@@ -1044,6 +1044,10 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin
return fmt.Sprintf("proxy_busy_buffers_size %s;", value)
},
},
"proxy-http-version": {
annotation: "nginx.ingress.kubernetes.io/proxy-http-version",
getter: nginxvhosts.ComputedProxyHttpVersion,
},
"proxy-connect-timeout": {
annotation: "nginx.ingress.kubernetes.io/proxy-connect-timeout",
getter: nginxvhosts.ComputedProxyConnectTimeout,

View File

@@ -103,6 +103,7 @@ assert_nginx_property_set_get() {
@test "(nginx:report) misc properties raw/global/computed" {
assert_nginx_property_set_get "disable-custom-config" "false" "true"
assert_nginx_property_set_get "underscore-in-headers" "on" "off"
assert_nginx_property_set_get "proxy-http-version" "2" "1.1"
assert_nginx_property_set_get "proxy-keepalive" "8" "16"
assert_nginx_property_set_get "nginx-conf-sigil-path" "custom.sigil" "global.sigil"
assert_nginx_property_set_get "nginx-service-command" "/usr/sbin/nginx-app" "/usr/sbin/nginx-global"