diff --git a/docs/networking/proxies/nginx.md b/docs/networking/proxies/nginx.md index 633a76030..3bf9bb6a6 100644 --- a/docs/networking/proxies/nginx.md +++ b/docs/networking/proxies/nginx.md @@ -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 | diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 21eeb9351..970f08062 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -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" diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions index 8016d4747..a2616eb84 100755 --- a/plugins/nginx-vhosts/internal-functions +++ b/plugins/nginx-vhosts/internal-functions @@ -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-http-version() { + 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" diff --git a/plugins/nginx-vhosts/nginx_vhosts.go b/plugins/nginx-vhosts/nginx_vhosts.go index 097314212..7a51f6e10 100644 --- a/plugins/nginx-vhosts/nginx_vhosts.go +++ b/plugins/nginx-vhosts/nginx_vhosts.go @@ -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-http-version") +} + func AppProxyConnectTimeout(appName string) string { return common.PropertyGet("nginx", appName, "proxy-connect-timeout") } diff --git a/plugins/nginx-vhosts/report.go b/plugins/nginx-vhosts/report.go index 7434118ff..3cf18eb3c 100644 --- a/plugins/nginx-vhosts/report.go +++ b/plugins/nginx-vhosts/report.go @@ -43,6 +43,7 @@ func nginxReportProps() []nginxReportProp { {"proxy-buffers", AppProxyBuffers, ComputedProxyBuffers, wrapGlobal(GlobalProxyBuffers)}, {"proxy-busy-buffers-size", AppProxyBusyBuffersSize, ComputedProxyBusyBuffersSize, wrapGlobal(GlobalProxyBusyBuffersSize)}, {"proxy-connect-timeout", AppProxyConnectTimeout, ComputedProxyConnectTimeout, wrapGlobal(GlobalProxyConnectTimeout)}, + {"proxy-http-version", AppProxyHttpVersion, ComputedProxyHttpVersion, wrapGlobal(GlobalProxyHttpVersion)}, {"proxy-keepalive", AppProxyKeepalive, ComputedProxyKeepalive, wrapGlobal(GlobalProxyKeepalive)}, {"proxy-read-timeout", AppProxyReadTimeout, ComputedProxyReadTimeout, wrapGlobal(GlobalProxyReadTimeout)}, {"proxy-send-timeout", AppProxySendTimeout, ComputedProxySendTimeout, wrapGlobal(GlobalProxySendTimeout)}, diff --git a/plugins/nginx-vhosts/src/nginx-property/nginx-property.go b/plugins/nginx-vhosts/src/nginx-property/nginx-property.go index 84d041a36..98b719b4d 100644 --- a/plugins/nginx-vhosts/src/nginx-property/nginx-property.go +++ b/plugins/nginx-vhosts/src/nginx-property/nginx-property.go @@ -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": diff --git a/plugins/nginx-vhosts/subcommands/set b/plugins/nginx-vhosts/subcommands/set index 27e85855b..ee8ad3530 100755 --- a/plugins/nginx-vhosts/subcommands/set +++ b/plugins/nginx-vhosts/subcommands/set @@ -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 diff --git a/plugins/nginx-vhosts/template_test.go b/plugins/nginx-vhosts/template_test.go index f1699656f..fa5beacc9 100644 --- a/plugins/nginx-vhosts/template_test.go +++ b/plugins/nginx-vhosts/template_test.go @@ -47,6 +47,7 @@ func defaultVars() map[string]interface{} { "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", diff --git a/plugins/nginx-vhosts/templates/nginx.conf.sigil b/plugins/nginx-vhosts/templates/nginx.conf.sigil index 9687e6a56..62f37ee0c 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.sigil +++ b/plugins/nginx-vhosts/templates/nginx.conf.sigil @@ -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 }}; diff --git a/plugins/scheduler-k3s/functions.go b/plugins/scheduler-k3s/functions.go index efe69fcc0..4a1050565 100644 --- a/plugins/scheduler-k3s/functions.go +++ b/plugins/scheduler-k3s/functions.go @@ -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, diff --git a/tests/unit/nginx-vhosts_properties.bats b/tests/unit/nginx-vhosts_properties.bats index db6792b21..fc1a5300a 100644 --- a/tests/unit/nginx-vhosts_properties.bats +++ b/tests/unit/nginx-vhosts_properties.bats @@ -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"