From 5da8bcc3b5721447b312c8bc5124adbc7104111e Mon Sep 17 00:00:00 2001 From: malixsys Date: Tue, 1 May 2018 12:58:16 -0400 Subject: [PATCH 1/2] Adding support for `http2_push_preload` to nginx 1.13.9+ configuration --- plugins/nginx-vhosts/functions | 26 ++++++++++++++++++- .../nginx-vhosts/templates/nginx.conf.sigil | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index fa4718605..4f57c7aaf 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -191,6 +191,28 @@ is_spdy_enabled() { echo $HAS_SUPPORT } +is_http2_push_enabled() { + declare desc="detects whether the installed nginx version has http2 push support" + local NGINX_VERSION="$1" + local MAJOR_VERSION MINOR_VERSION PATCH_VERSION + local HAS_SUPPORT=false + + MAJOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[1]}') + MINOR_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[2]}') + PATCH_VERSION=$(echo "$NGINX_VERSION" | awk '{split($0,a,"."); print a[3]}') + if [[ "$MAJOR_VERSION" -ge "2" ]]; then + HAS_SUPPORT=true + elif [[ "$MAJOR_VERSION" -eq "1" ]]; then + if [[ "$MINOR_VERSION" -eq "13" ]] && [[ "$PATCH_VERSION" -ge "9" ]]; then + HAS_SUPPORT=true + elif [[ "$MINOR_VERSION" -ge "14" ]]; then + HAS_SUPPORT=true + fi + fi + + echo $HAS_SUPPORT +} + is_http2_enabled() { declare desc="detects whether the installed nginx version has http2 support" local NGINX_VERSION="$1" @@ -285,7 +307,7 @@ nginx_build_config() { done fi - local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED HTTP2_SUPPORTED + local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED HTTP2_SUPPORTED HTTP2_PUSH_SUPPORTED NGINX_LOCATION=$(get_nginx_location) if [[ -z "$NGINX_LOCATION" ]]; then exit 1; @@ -293,6 +315,7 @@ nginx_build_config() { NGINX_VERSION="$("$NGINX_LOCATION" -v 2>&1 | cut -d'/' -f 2)" SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")" HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")" + HTTP2_PUSH_SUPPORTED="$(is_http2_push_enabled "$NGINX_VERSION")" PROXY_PORT_MAP=$(echo "$PROXY_PORT_MAP" | xargs) # trailing spaces mess up default template @@ -304,6 +327,7 @@ nginx_build_config() { PASSED_LISTEN_IP_PORT="$PASSED_LISTEN_IP_PORT" SPDY_SUPPORTED="$SPDY_SUPPORTED" HTTP2_SUPPORTED="$HTTP2_SUPPORTED" + HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_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" # @TODO: Remove this after a few versions diff --git a/plugins/nginx-vhosts/templates/nginx.conf.sigil b/plugins/nginx-vhosts/templates/nginx.conf.sigil index 3f2036fdf..5f46a4ff2 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.sigil +++ b/plugins/nginx-vhosts/templates/nginx.conf.sigil @@ -81,6 +81,9 @@ server { gzip_comp_level 6; proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; + {{ if (eq $.HTTP2_PUSH_SUPPORTED "true")}} + http2_push_preload on; + {{ end }} proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; From 136c8689047e56465d21765b637ff7bed8587b33 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 19 May 2018 02:14:37 -0400 Subject: [PATCH 2/2] chore: move http2_push logic into single line [ci skip] --- plugins/nginx-vhosts/templates/nginx.conf.sigil | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/nginx-vhosts/templates/nginx.conf.sigil b/plugins/nginx-vhosts/templates/nginx.conf.sigil index 5f46a4ff2..360ba4a6a 100644 --- a/plugins/nginx-vhosts/templates/nginx.conf.sigil +++ b/plugins/nginx-vhosts/templates/nginx.conf.sigil @@ -81,9 +81,7 @@ server { gzip_comp_level 6; proxy_pass http://{{ $.APP }}-{{ $upstream_port }}; - {{ if (eq $.HTTP2_PUSH_SUPPORTED "true")}} - http2_push_preload on; - {{ end }} + {{ if eq $.HTTP2_PUSH_SUPPORTED "true" }}http2_push_preload on; {{ end }} proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";