diff --git a/conf/nginx.conf.server.template b/conf/nginx.conf.server.template index d56f5e6..450ce57 100644 --- a/conf/nginx.conf.server.template +++ b/conf/nginx.conf.server.template @@ -153,7 +153,7 @@ server { ## The time here is overridden by our injected `expires $cache_expiry` header. proxy_cache_valid 200 206 1s; - access_log ${LOG_DIR}/cache.log proxy_cache; + ${CACHE_ACCESS_LOG_DIRECTIVE} } } @@ -241,7 +241,7 @@ server { proxy_ssl_trusted_certificate ./cacert.pem; proxy_ssl_server_name on; - access_log ${LOG_DIR}/range_cache.log range_cache; + ${RANGE_ACCESS_LOG_DIRECTIVE} } } diff --git a/conf/nginx.conf.template b/conf/nginx.conf.template index 4ad14be..3417a51 100644 --- a/conf/nginx.conf.template +++ b/conf/nginx.conf.template @@ -41,8 +41,8 @@ http { # Logging Settings ## - access_log ${LOG_DIR}/access.log; - error_log ${LOG_DIR}/error.log; + ${ACCESS_LOG_DIRECTIVE} + error_log stderr ${ERROR_LOG_LEVEL}; log_format proxy_cache '$remote_addr – $upstream_cache_status $status [$time_local] $request_method $proxy_method://$host$uri $body_bytes_sent "$http_referer" "$http_user_agent" '; diff --git a/scripts/generate_conf_files.sh b/scripts/generate_conf_files.sh index 2639a81..3a98ae5 100644 --- a/scripts/generate_conf_files.sh +++ b/scripts/generate_conf_files.sh @@ -53,6 +53,22 @@ then export LOG_DIR="./logs" fi +if [ "$ENABLE_ACCESS_LOGS" = "true" ]; then + export ACCESS_LOG_DIRECTIVE="access_log ${LOG_DIR}/access.log;" + export CACHE_ACCESS_LOG_DIRECTIVE="access_log ${LOG_DIR}/cache.log proxy_cache;" + export RANGE_ACCESS_LOG_DIRECTIVE="access_log ${LOG_DIR}/range_cache.log range_cache;" +else + export ACCESS_LOG_DIRECTIVE="access_log off;" + export CACHE_ACCESS_LOG_DIRECTIVE="access_log off;" + export RANGE_ACCESS_LOG_DIRECTIVE="access_log off;" +fi + +# Levels can be warn, error crit, alert, and emerg. +if [ -z "$ERROR_LOG_LEVEL" ] +then + export ERROR_LOG_LEVEL="crit" +fi + if [ -z "$CONTENT_CACHE_DIR" ] then export CONTENT_CACHE_DIR="/data/funes/content_cache" @@ -131,7 +147,10 @@ if [ -z "$PROXY_READ_DATA_TIMEOUT" ] then export PROXY_READ_DATA_TIMEOUT="60s" fi - +printf 'ERROR_LOG_LEVEL=%s\n' "$ERROR_LOG_LEVEL" +printf 'ACCESS_LOG_DIRECTIVE=%s\n' "$ACCESS_LOG_DIRECTIVE" +printf 'CACHE_ACCESS_LOG_DIRECTIVE=%s\n' "$CACHE_ACCESS_LOG_DIRECTIVE" +printf 'RANGE_ACCESS_LOG_DIRECTIVE=%s\n' "$RANGE_ACCESS_LOG_DIRECTIVE" printf 'LOG_DIR=%s\n' "$LOG_DIR" printf 'CONTENT_CACHE_DIR=%s\n' "$CONTENT_CACHE_DIR" printf 'CONTENT_CACHE_KEYS_ZONE=%s\n' "$CONTENT_CACHE_KEYS_ZONE" @@ -155,6 +174,6 @@ fi echo "Nameserver is: $NAMESERVER" echo "Copying nginx config" -envsubst '${ROOT_CA_CERT} ${ROOT_CA_KEY} ${LOG_DIR} ${PROXY_BUFFER_SIZE} ${PROXY_BUFFERS} ${PROXY_BUSY_BUFFERS_SIZE}' < ./conf/nginx.conf.template > ./conf/nginx.conf -envsubst '${PROXY_CONNECT_DATA_TIMEOUT} ${PROXY_READ_DATA_TIMEOUT} ${NAMESERVER} ${LOG_DIR} ${CONTENT_CACHE_DIR} ${CONTENT_CACHE_KEYS_ZONE} ${CONTENT_CACHE_SIZE} ${SSL_VERIFY_DEPTH}' < ./conf/nginx.conf.server.template > ./conf/nginx.conf.server +envsubst '${ROOT_CA_CERT} ${ROOT_CA_KEY} ${ERROR_LOG_LEVEL} ${ACCESS_LOG_DIRECTIVE} ${PROXY_BUFFER_SIZE} ${PROXY_BUFFERS} ${PROXY_BUSY_BUFFERS_SIZE}' < ./conf/nginx.conf.template > ./conf/nginx.conf +envsubst '${PROXY_CONNECT_DATA_TIMEOUT} ${PROXY_READ_DATA_TIMEOUT} ${NAMESERVER} ${CACHE_ACCESS_LOG_DIRECTIVE} ${RANGE_ACCESS_LOG_DIRECTIVE} ${CONTENT_CACHE_DIR} ${CONTENT_CACHE_KEYS_ZONE} ${CONTENT_CACHE_SIZE} ${SSL_VERIFY_DEPTH}' < ./conf/nginx.conf.server.template > ./conf/nginx.conf.server envsubst '${ROOT_CA_CERT} ${ROOT_CA_KEY} ${CERT_MEM_CACHE_TTL_SEC}' < ./conf/generate_ssl_certs.template.lua > ./conf/generate_ssl_certs.lua