-
Notifications
You must be signed in to change notification settings - Fork 1
/
nginx-pre-reload
executable file
·26 lines (22 loc) · 1.49 KB
/
nginx-pre-reload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
nginx-vhost-trustproxy-hook-nginx-pre-reload() {
[[ -z $1 ]] && dokku_log_fail "Please specify an app to run the command on"
verify_app_name "$1"
local APP="$1";
local NGINX_VHOST_TRUSTPROXY=$(config_get $APP NGINX_VHOST_TRUSTPROXY)
if [[ "$NGINX_VHOST_TRUSTPROXY" = "" ]]; then
# revert back to the original
sed -i 's/proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto/proxy_set_header X-Forwarded-Proto $scheme/g' $DOKKU_ROOT/$APP/nginx.conf
sed -i 's/proxy_set_header X-Forwarded-For $http_x_forwarded_for/proxy_set_header X-Forwarded-For $remote_addr/g' $DOKKU_ROOT/$APP/nginx.conf
sed -i 's/proxy_set_header X-Forwarded-Port $http_x_forwarded_porto/proxy_set_header X-Forwarded-Port $server_port/g' $DOKKU_ROOT/$APP/nginx.conf
else
dokku_log_info1 "Adding nginx-vhost-trustproxy configuration for app ($APP)."
sed -i 's/proxy_set_header X-Forwarded-Proto $scheme/proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto/g' $DOKKU_ROOT/$APP/nginx.conf
sed -i 's/proxy_set_header X-Forwarded-For $remote_addr/proxy_set_header X-Forwarded-For $http_x_forwarded_for/g' $DOKKU_ROOT/$APP/nginx.conf
sed -i 's/proxy_set_header X-Forwarded-Port $server_port/proxy_set_header X-Forwarded-Port $http_x_forwarded_porto/g' $DOKKU_ROOT/$APP/nginx.conf
fi
}
nginx-vhost-trustproxy-hook-nginx-pre-reload $@