nginx-vhost: add support for grpc/grpcs port forward
This commit is contained in:
2 files changed
+61
-1
No files matched your search
@@ -259,6 +259,29 @@ is_http2_enabled() {
|
|||||||
echo $HAS_SUPPORT
|
echo $HAS_SUPPORT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_grpc_enabled() {
|
||||||
|
declare desc="detects whether the installed nginx version has grpc 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 "10" ]]; then
|
||||||
|
HAS_SUPPORT=true
|
||||||
|
elif [[ "$MINOR_VERSION" -ge "14" ]]; then
|
||||||
|
HAS_SUPPORT=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $HAS_SUPPORT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
nginx_build_config() {
|
nginx_build_config() {
|
||||||
declare desc="build nginx config to proxy app containers using sigil"
|
declare desc="build nginx config to proxy app containers using sigil"
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
@@ -337,7 +360,7 @@ nginx_build_config() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED HTTP2_SUPPORTED HTTP2_PUSH_SUPPORTED
|
local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED HTTP2_SUPPORTED HTTP2_PUSH_SUPPORTED GRPC_SUPPORTED
|
||||||
NGINX_LOCATION=$(get_nginx_location)
|
NGINX_LOCATION=$(get_nginx_location)
|
||||||
if [[ -z "$NGINX_LOCATION" ]]; then
|
if [[ -z "$NGINX_LOCATION" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
@@ -346,6 +369,7 @@ nginx_build_config() {
|
|||||||
SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
|
SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")"
|
||||||
HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
|
HTTP2_SUPPORTED="$(is_http2_enabled "$NGINX_VERSION")"
|
||||||
HTTP2_PUSH_SUPPORTED="$(is_http2_push_enabled "$NGINX_VERSION")"
|
HTTP2_PUSH_SUPPORTED="$(is_http2_push_enabled "$NGINX_VERSION")"
|
||||||
|
GRPC_SUPPORTED="$(is_grpc_enabled "$NGINX_VERSION")"
|
||||||
|
|
||||||
PROXY_PORT_MAP=$(echo "$PROXY_PORT_MAP" | xargs) # trailing spaces mess up default template
|
PROXY_PORT_MAP=$(echo "$PROXY_PORT_MAP" | xargs) # trailing spaces mess up default template
|
||||||
|
|
||||||
@@ -358,6 +382,7 @@ nginx_build_config() {
|
|||||||
SPDY_SUPPORTED="$SPDY_SUPPORTED"
|
SPDY_SUPPORTED="$SPDY_SUPPORTED"
|
||||||
HTTP2_SUPPORTED="$HTTP2_SUPPORTED"
|
HTTP2_SUPPORTED="$HTTP2_SUPPORTED"
|
||||||
HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_SUPPORTED"
|
HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_SUPPORTED"
|
||||||
|
GRPC_SUPPORTED="$GRPC_SUPPORTED"
|
||||||
DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP"
|
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"
|
APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME"
|
||||||
# @TODO: Remove this after a few versions
|
# @TODO: Remove this after a few versions
|
||||||
|
|||||||
@@ -117,7 +117,42 @@ server {
|
|||||||
internal;
|
internal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{{ else if eq $scheme "grpc"}}
|
||||||
|
{{ if eq $.GRPC_SUPPORTED "true"}}{{ if eq $.HTTP2_SUPPORTED "true"}}
|
||||||
|
server {
|
||||||
|
listen [::]:{{ $listen_port }} http2;
|
||||||
|
listen {{ $listen_port }} http2;
|
||||||
|
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
|
||||||
|
access_log /var/log/nginx/{{ $.APP }}-access.log;
|
||||||
|
error_log /var/log/nginx/{{ $.APP }}-error.log;
|
||||||
|
location / {
|
||||||
|
grpc_pass grpc://{{ $.APP }}-{{ $upstream_port }};
|
||||||
|
}
|
||||||
|
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
||||||
|
}
|
||||||
{{ end }}{{ end }}
|
{{ end }}{{ end }}
|
||||||
|
{{ else if eq $scheme "grpcs"}}
|
||||||
|
{{ if eq $.GRPC_SUPPORTED "true"}}{{ if eq $.HTTP2_SUPPORTED "true"}}
|
||||||
|
server {
|
||||||
|
listen [::]:{{ $listen_port }} ssl http2;
|
||||||
|
listen {{ $listen_port }} ssl http2;
|
||||||
|
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
|
||||||
|
access_log /var/log/nginx/{{ $.APP }}-access.log;
|
||||||
|
error_log /var/log/nginx/{{ $.APP }}-error.log;
|
||||||
|
|
||||||
|
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
|
||||||
|
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
|
||||||
|
ssl_protocols TLSv1.2;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
grpc_pass grpc://{{ $.APP }}-{{ $upstream_port }};
|
||||||
|
}
|
||||||
|
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
||||||
|
}
|
||||||
|
{{ end }}{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ if $.DOKKU_APP_LISTENERS }}
|
{{ if $.DOKKU_APP_LISTENERS }}
|
||||||
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
|
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
|
||||||
|
|||||||
Reference in new issue
Block a user