feat: allow controlling proxy-read-timeout

Closes #4042
This commit is contained in:
Jose Diaz-Gonzalez
2020-07-01 19:08:15 -04:00
parent 64993a57eb
commit 42122a7540
6 changed files with 67 additions and 5 deletions

View File

@@ -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.

View File

@@ -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")"
)

View File

@@ -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"

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-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

View File

@@ -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;

View File

@@ -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"