feat: add ability to change or disable the access/error log path
Closes #3911
This commit is contained in:
@@ -37,8 +37,10 @@ cmd-nginx-report-single() {
|
||||
fi
|
||||
verify_app_name "$APP"
|
||||
local flag_map=(
|
||||
"--nginx-access-log-path: $(fn-nginx-access-log-path "$APP")"
|
||||
"--nginx-bind-address-ipv4: $(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv4" "")"
|
||||
"--nginx-bind-address-ipv6: $(fn-plugin-property-get-default "nginx" "$APP" "bind-address-ipv6" "::")"
|
||||
"--nginx-error-log-path: $(fn-nginx-error-log-path "$APP")"
|
||||
"--nginx-hsts: $(fn-plugin-property-get-default "nginx" "$APP" "hsts" "true")"
|
||||
"--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")"
|
||||
|
||||
@@ -8,6 +8,29 @@ source "$PLUGIN_AVAILABLE_PATH/domains/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions"
|
||||
|
||||
fn-nginx-log-root() {
|
||||
declare desc="get the nginx log root"
|
||||
local NGINX_LOG_ROOT="/var/log/nginx"
|
||||
fn-nginx-vhosts-uses-openresty && NGINX_LOG_ROOT="/var/log/openresty"
|
||||
echo "$NGINX_LOG_ROOT"
|
||||
}
|
||||
|
||||
fn-nginx-access-log-path() {
|
||||
declare desc="get the configured access log path"
|
||||
declare APP="$1"
|
||||
local NGINX_LOG_ROOT="$(fn-nginx-log-root)"
|
||||
|
||||
fn-plugin-property-get-default "nginx" "$APP" "access-log-path" "${NGINX_LOG_ROOT}/${APP}-access.log"
|
||||
}
|
||||
|
||||
fn-nginx-error-log-path() {
|
||||
declare desc="get the configured access log path"
|
||||
declare APP="$1"
|
||||
local NGINX_LOG_ROOT="$(fn-nginx-log-root)"
|
||||
|
||||
fn-plugin-property-get-default "nginx" "$APP" "error-log-path" "${NGINX_LOG_ROOT}/${APP}-error.log"
|
||||
}
|
||||
|
||||
get_nginx_location() {
|
||||
declare desc="check that nginx is at the expected location and return it"
|
||||
fn-nginx-vhosts-nginx-location
|
||||
@@ -63,12 +86,14 @@ restart_nginx() {
|
||||
nginx_logs() {
|
||||
declare desc="display app nginx logs"
|
||||
declare NGINX_LOGS_TYPE="${1#nginx:}" APP="$2"
|
||||
local NGINX_LOG_ROOT="/var/log/nginx"
|
||||
verify_app_name "$APP"
|
||||
|
||||
fn-nginx-vhosts-uses-openresty && NGINX_LOG_ROOT="/var/log/openresty"
|
||||
local NGINX_LOGS_TYPE=${NGINX_LOGS_TYPE%-logs}
|
||||
local NGINX_LOGS_PATH="$NGINX_LOG_ROOT/$APP-$NGINX_LOGS_TYPE.log"
|
||||
local NGINX_LOGS_PATH="$("fn-nginx-${NGINX_LOGS_TYPE}-log-path" "$APP")"
|
||||
|
||||
if [[ "$NGINX_LOGS_PATH" == "off" ]] || [[ "$NGINX_LOGS_PATH" == "/dev/null" ]]; then
|
||||
dokku_log_fail "$NGINX_LOGS_TYPE logs are disabled for this app"
|
||||
fi
|
||||
|
||||
if [[ $3 == "-t" ]]; then
|
||||
local NGINX_LOGS_ARGS="-F"
|
||||
@@ -355,8 +380,9 @@ nginx_build_config() {
|
||||
|
||||
PROXY_PORT_MAP=$(echo "$PROXY_PORT_MAP" | xargs) # trailing spaces mess up default template
|
||||
|
||||
local NGINX_LOG_ROOT="/var/log/nginx"
|
||||
fn-nginx-vhosts-uses-openresty && NGINX_LOG_ROOT="/var/log/openresty"
|
||||
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")"
|
||||
|
||||
if [[ -z "$DOKKU_APP_LISTENERS" ]]; then
|
||||
dokku_log_warn_quiet "No web listeners specified for $APP"
|
||||
@@ -384,6 +410,9 @@ 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"
|
||||
@@ -395,6 +424,8 @@ nginx_build_config() {
|
||||
TLS13_SUPPORTED="$TLS13_SUPPORTED"
|
||||
HTTP2_SUPPORTED="$HTTP2_SUPPORTED"
|
||||
NGINX_LOG_ROOT="$NGINX_LOG_ROOT"
|
||||
NGINX_ACCESS_LOG_PATH="$NGINX_ACCESS_LOG_PATH"
|
||||
NGINX_ERROR_LOG_PATH="$NGINX_ERROR_LOG_PATH"
|
||||
NGINX_BIND_ADDRESS_IP4="$NGINX_BIND_ADDRESS_IP4"
|
||||
NGINX_BIND_ADDRESS_IP6="$NGINX_BIND_ADDRESS_IP6"
|
||||
HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_SUPPORTED"
|
||||
|
||||
@@ -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=("bind-address-ipv4" "bind-address-ipv6" "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")
|
||||
|
||||
[[ -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: bind-address-ipv4, bind-address-ipv6, 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"
|
||||
fi
|
||||
|
||||
if [[ -n "$VALUE" ]]; then
|
||||
|
||||
@@ -9,8 +9,8 @@ server {
|
||||
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }};
|
||||
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }};
|
||||
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
|
||||
access_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-access.log;
|
||||
error_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-error.log;
|
||||
access_log {{ $.NGINX_ACCESS_LOG_PATH }};
|
||||
error_log {{ $.NGINX_ERROR_LOG_PATH }};
|
||||
{{ if (and (eq $listen_port "80") ($.SSL_INUSE)) }}
|
||||
return 301 https://$host:{{ $.PROXY_SSL_PORT }}$request_uri;
|
||||
{{ else }}
|
||||
@@ -60,8 +60,8 @@ server {
|
||||
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} ssl {{ if eq $.HTTP2_SUPPORTED "true" }}http2{{ else if eq $.SPDY_SUPPORTED "true" }}spdy{{ end }};
|
||||
{{ if $.SSL_SERVER_NAME }}server_name {{ $.SSL_SERVER_NAME }}; {{ end }}
|
||||
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
|
||||
access_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-access.log;
|
||||
error_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-error.log;
|
||||
access_log {{ $.NGINX_ACCESS_LOG_PATH }};
|
||||
error_log {{ $.NGINX_ERROR_LOG_PATH }};
|
||||
|
||||
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
|
||||
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
|
||||
@@ -123,8 +123,8 @@ server {
|
||||
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} http2;
|
||||
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} http2;
|
||||
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
|
||||
access_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-access.log;
|
||||
error_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-error.log;
|
||||
access_log {{ $.NGINX_ACCESS_LOG_PATH }};
|
||||
error_log {{ $.NGINX_ERROR_LOG_PATH }};
|
||||
location / {
|
||||
grpc_pass grpc://{{ $.APP }}-{{ $upstream_port }};
|
||||
}
|
||||
@@ -137,8 +137,8 @@ server {
|
||||
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} ssl http2;
|
||||
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} ssl http2;
|
||||
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
|
||||
access_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-access.log;
|
||||
error_log {{ $.NGINX_LOG_ROOT }}/{{ $.APP }}-error.log;
|
||||
access_log {{ $.NGINX_ACCESS_LOG_PATH }};
|
||||
error_log {{ $.NGINX_ERROR_LOG_PATH }};
|
||||
|
||||
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
|
||||
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
|
||||
|
||||
Reference in New Issue
Block a user