diff --git a/docs/configuration/nginx.md b/docs/configuration/nginx.md index c0dc6a9bb..0140ded6e 100644 --- a/docs/configuration/nginx.md +++ b/docs/configuration/nginx.md @@ -106,6 +106,26 @@ dokku nginx:set node-js-app error-log-path In all cases, the nginx config must be regenerated after setting the above values. +## Specifying a read timeout + +> New as of 0.21.0 + +When proxying requests to your applications, it may be useful to specify a proxy read timeout. This can be done via the `nginx:set` command as follows: + +```shell +dokku nginx:set node-js-app proxy-read-timeout 120s +``` + +The default value is `60s`, and all numeric values _must_ have a trailing time value specified (`s` for seconds, `m` for minutes). + +The default value may be set by passing an empty value for the option: + +```shell +dokku nginx:set node-js-app proxy-read-timeout +``` + +In all cases, the nginx config must be regenerated after setting the above value. + ## Showing the nginx config For debugging purposes, it may be useful to show the nginx config. This can be achieved via the `nginx:show-config` command. diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index 59776be15..21ed3ddc2 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -46,6 +46,7 @@ cmd-nginx-report-single() { "--nginx-hsts-include-subdomains: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-include-subdomains" "true")" "--nginx-hsts-max-age: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-max-age" "15724800")" "--nginx-hsts-preload: $(fn-plugin-property-get-default "nginx" "$APP" "hsts-preload" "false")" + "--nginx-proxy-read-timeout: $(fn-nginx-proxy-read-timeout "$APP")" "--nginx-last-visited-at: $(fn-nginx-vhosts-last-visited-at "$APP")" ) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 4a8e9e672..d46d1610d 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -22,6 +22,13 @@ fn-nginx-access-log-path() { fn-plugin-property-get-default "nginx" "$APP" "access-log-path" "${NGINX_LOG_ROOT}/${APP}-access.log" } +fn-nginx-proxy-read-timeout() { + declare desc="get the configured proxy read timeout" + declare APP="$1" + + fn-plugin-property-get-default "nginx" "$APP" "proxy-read-timeout" "60s" +} + fn-nginx-error-log-path() { declare desc="get the configured access log path" declare APP="$1" @@ -385,6 +392,7 @@ nginx_build_config() { local NGINX_LOG_ROOT="$(fn-nginx-log-root)" local NGINX_ACCESS_LOG_PATH="$(fn-nginx-access-log-path "$APP")" local NGINX_ERROR_LOG_PATH="$(fn-nginx-error-log-path "$APP")" + local PROXY_READ_TIMEOUT="$(fn-nginx-proxy-read-timeout "$APP")" if [[ -z "$DOKKU_APP_LISTENERS" ]]; then dokku_log_warn_quiet "No web listeners specified for $APP" @@ -412,9 +420,6 @@ nginx_build_config() { local NGINX_BIND_ADDRESS_IP6="$(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv6" "::")" [[ -z "$NGINX_BIND_ADDRESS_IP6" ]] && NGINX_BIND_ADDRESS_IP6="::" - local NGINX_ACCESS_LOGS_ENABLED="$(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv4" "")" - local NGINX_ERROR_LOGS_ENABLED="$(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv6" "::")" - eval "$(config_export app "$APP")" local SIGIL_PARAMS=(-f "$NGINX_TEMPLATE" APP="$APP" DOKKU_ROOT="$DOKKU_ROOT" NOSSL_SERVER_NAME="$NOSSL_SERVER_NAME" @@ -434,6 +439,7 @@ nginx_build_config() { GRPC_SUPPORTED="$GRPC_SUPPORTED" DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP" APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME" + PROXY_READ_TIMEOUT="$PROXY_READ_TIMEOUT" # Deprecated: Remove this after a few versions NGINX_PORT="$PROXY_PORT" NGINX_SSL_PORT="$PROXY_SSL_PORT" PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" diff --git a/plugins/nginx-vhosts/subcommands/set b/plugins/nginx-vhosts/subcommands/set index cec931169..e99f94c28 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-path" "bind-address-ipv4" "bind-address-ipv6" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age") + local VALID_KEYS=("access-log-path" "bind-address-ipv4" "bind-address-ipv6" "error-log-path" "hsts" "hsts-include-subdomains" "hsts-preload" "hsts-max-age" "proxy-read-timeout") [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" [[ -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-path, bind-address-ipv4, bind-address-ipv6, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age" + dokku_log_fail "Invalid key specified, valid keys include: access-log-path, bind-address-ipv4, bind-address-ipv6, error-log-path, hsts, hsts-include-subdomains, hsts-preload, hsts-max-age, proxy-read-timeout" fi if [[ -n "$VALUE" ]]; then diff --git a/plugins/nginx-vhosts/templates/nginx.conf.sigil b/plugins/nginx-vhosts/templates/nginx.conf.sigil index b1d6d1a24..a85f942e3 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.sigil +++ b/plugins/nginx-vhosts/templates/nginx.conf.sigil @@ -25,6 +25,7 @@ server { proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; proxy_http_version 1.1; + proxy_read_timeout {{ $.PROXY_READ_TIMEOUT }}; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Host $http_host; diff --git a/tests/unit/nginx-vhosts_8.bats b/tests/unit/nginx-vhosts_8.bats index c90095a02..857ea2182 100644 --- a/tests/unit/nginx-vhosts_8.bats +++ b/tests/unit/nginx-vhosts_8.bats @@ -104,6 +104,40 @@ teardown() { assert_output_contains "off;" 0 } +@test "(nginx-vhosts) nginx:set proxy-read-timeout" { + deploy_app + + run /bin/bash -c "dokku nginx:set $TEST_APP proxy-read-timeout 45s" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "45s;" + + run /bin/bash -c "dokku nginx:set $TEST_APP proxy-read-timeout" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "45s;" 0 +} + @test "(nginx-vhosts) nginx:build-config (with SSL and unrelated domain)" { setup_test_tls add_domain "node-js-app.dokku.me"