diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index ea3153a..0ac8693 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -12,6 +12,12 @@ export PHP_PORT="${PHP_PORT:-9000}" export NGINX_PHP_READ_TIMEOUT="${NGINX_PHP_READ_TIMEOUT:-900}" export NGINX_CATCHALL_RETURN_CODE="${NGINX_CATCHALL_RETURN_CODE:-444}" +export NGINX_ACCESS_LOG_FORMAT="${NGINX_ACCESS_LOG_FORMAT:-main}" +# If the environment is not local, we enable structured logging. +if [ "${ENV:-}" != "loc" ]; then + export NGINX_ACCESS_LOG_FORMAT="structured" +fi + # If you use the rootless image the user directive is not needed if [ "$(id -u)" -ne 0 ]; then sed -i '/^user /d' /etc/nginx/nginx.conf @@ -107,10 +113,9 @@ if [ "${NGINX_DEFAULT_SERVER_NAME}" = "_" ]; then else export DEFAULT_SERVER="" # shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion - envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${NGINX_SUBFOLDER} ${NGINX_SUBFOLDER_ESCAPED} ${NGINX_CATCHALL_RETURN_CODE} ${NGINX_HSTS_HEADER}' < /templates/catch-all-server.conf > /etc/nginx/conf.d/catch-all-server.conf + envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${NGINX_SUBFOLDER} ${NGINX_SUBFOLDER_ESCAPED} ${NGINX_CATCHALL_RETURN_CODE} ${NGINX_HSTS_HEADER}' < /templates/catch-all-server.conf > /etc/nginx/conf.d/catch-all-server.conf fi -export NGINX_ACCESS_LOG_FORMAT="${NGINX_ACCESS_LOG_FORMAT:-main}" export NGINX_DEFAULT_ROOT="${NGINX_DEFAULT_ROOT:-/var/www/html}" export NGINX_HTTPSREDIRECT="${NGINX_HTTPSREDIRECT:-0}" export NGINX_SUBFOLDER="${NGINX_SUBFOLDER:-0}" @@ -142,11 +147,6 @@ if [ "${NGINX_OSB_RESOLVER_ENFORCE_IPV6_OFF}" = "1" ] && ! echo "${NGINX_OSB_RES export NGINX_OSB_RESOLVER="${NGINX_OSB_RESOLVER} ipv6=off" fi -# If the environment is not local, we enable structured logging. -if [ "${ENV:-}" != "loc" ]; then - export NGINX_ACCESS_LOG_FORMAT="structured" -fi - # These lines of code have been added to provide a BC path for those # environments that still have the NGINX_OSB_BUCKET variable filled with the # old format that consist in having the value of NGINX_OSB_PUBLIC_PATH (usually @@ -239,7 +239,7 @@ envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_DEFAULT_SER if [ "${NGINX_SUBFOLDER}" != 0 ]; then # shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion - envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${NGINX_SUBFOLDER} ${NGINX_SUBFOLDER_ESCAPED} ${NGINX_XFRAME_OPTION_VALUE} ${NGINX_HSTS_HEADER}' < /templates/subfolder.conf > /etc/nginx/conf.d/default.conf + envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${NGINX_SUBFOLDER} ${NGINX_SUBFOLDER_ESCAPED} ${NGINX_XFRAME_OPTION_VALUE} ${NGINX_HSTS_HEADER}' < /templates/subfolder.conf > /etc/nginx/conf.d/default.conf fi # Handle robots.txt and sitemap directive @@ -344,7 +344,7 @@ if [ "${NGINX_REDIRECT_FROM_TO_WWW}" -eq 1 ] && [ "${NGINX_DEFAULT_SERVER_NAME}" print "/etc/nginx/conf.d/from-to-www.conf - Creating a redirect from ${DOMAIN_FROM} to ${DOMAIN_TO}" # shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion DOMAIN_FROM=${DOMAIN_FROM} DOMAIN_TO=${DOMAIN_TO} \ - envsubst '${DOMAIN_FROM} ${DOMAIN_TO} ${NGINX_DEFAULT_SERVER_PORT} ${DEFAULT_SERVER} ${NGINX_HSTS_HEADER}' < /templates/from-to-www.conf.tpl \ + envsubst '${DOMAIN_FROM} ${DOMAIN_TO} ${NGINX_DEFAULT_SERVER_PORT} ${DEFAULT_SERVER} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_HSTS_HEADER}' < /templates/from-to-www.conf.tpl \ | tee -a /etc/nginx/conf.d/from-to-www.conf >/dev/null else print "/etc/nginx/conf.d/from-to-www.conf - Skipping redirect from ${DOMAIN_FROM} to ${DOMAIN_TO} because it already exists" diff --git a/templates/catch-all-server.conf b/templates/catch-all-server.conf index f78a89f..c1beef1 100644 --- a/templates/catch-all-server.conf +++ b/templates/catch-all-server.conf @@ -7,6 +7,8 @@ map $scheme://$host$request_uri $new_domain_uri { } server { + access_log /var/log/nginx/access.log ${NGINX_ACCESS_LOG_FORMAT}; + listen ${NGINX_DEFAULT_SERVER_PORT} default_server; # The _ it is just one of a myriad of invalid domain diff --git a/templates/from-to-www.conf.tpl b/templates/from-to-www.conf.tpl index 9510502..bb4ee67 100644 --- a/templates/from-to-www.conf.tpl +++ b/templates/from-to-www.conf.tpl @@ -1,8 +1,12 @@ server { + access_log /var/log/nginx/access.log ${NGINX_ACCESS_LOG_FORMAT}; + server_name ${DOMAIN_FROM}; listen ${NGINX_DEFAULT_SERVER_PORT} ${DEFAULT_SERVER}; + #hstsheader #httpsredirect + set $request_proto $scheme; if ($http_x_forwarded_proto = "https") { set $request_proto "https"; diff --git a/templates/subfolder.conf b/templates/subfolder.conf index 05f84e3..23fd058 100644 --- a/templates/subfolder.conf +++ b/templates/subfolder.conf @@ -9,6 +9,8 @@ map $http_x_forwarded_proto $fastcgi_https { } server { + access_log /var/log/nginx/access.log ${NGINX_ACCESS_LOG_FORMAT}; + server_name ${NGINX_DEFAULT_SERVER_NAME}; listen ${NGINX_DEFAULT_SERVER_PORT}; @@ -22,7 +24,6 @@ server { include /etc/nginx/conf.d/fragments/*.conf; - # Just return for google gclb healthcheck. if ($http_user_agent = 'GoogleHC/1.0') { return 200;