From bfdb85b384f4ed37f396814c2d04d36466a11d58 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Fri, 18 Oct 2019 01:53:20 -0600 Subject: [PATCH] add option to turn on access log --- ab-nginx.params.template | 7 ++++++- build/Dockerfile | 1 + build/config/nginx.conf | 3 +-- build/entrypoint.sh | 11 +++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ab-nginx.params.template b/ab-nginx.params.template index 3ce2c3c..8949623 100644 --- a/ab-nginx.params.template +++ b/ab-nginx.params.template @@ -1,7 +1,7 @@ ##### # Parameters for use by ab-nginx convenience script # -# NOTE: 'TRUE' and 'FALSE' MUST BE IN CAPITALS! +# NOTE: 'TRUE', 'FALSE', 'ON' and 'OFF' MUST be in all CAPITALS! # # If you are not using the 'ab-nginx.sh' script file to start the container, # then you don't have to do anything with this file. @@ -34,6 +34,11 @@ SERVER_NAMES="domain.tld www.domain.tld server.domain.tld alt.domain.tld" HTTP_PORT=80 HTTPS_PORT=443 +# Access logging (global preference): +# Unless overridden in a server/location block, access logging will be handled +# according to this setting. Default is OFF. Choices are 'ON' or 'OFF'. Logs +# will be printed to the console so they are accessible via 'docker logs ...' +ACCESS_LOG=OFF ### Content files # Whatever you specify here will replace the default files in the container diff --git a/build/Dockerfile b/build/Dockerfile index 4311ec8..35377db 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -35,6 +35,7 @@ ENV TZ=Etc/UTC ENV SERVER_NAMES="_" ENV HTTP_PORT=80 ENV HTTPS_PORT=443 +ENV ACCESS_LOG=OFF ENV HSTS=FALSE ENV TLS13_ONLY=FALSE diff --git a/build/config/nginx.conf b/build/config/nginx.conf index 90140fc..9fc47f6 100644 --- a/build/config/nginx.conf +++ b/build/config/nginx.conf @@ -35,8 +35,7 @@ http { 'uaddr="$upstream_addr" ustat="$upstream_status" ' 'utime="$upstream_response_time" ulen="$upstream_response_length" ' 'cache="$upstream_cache_status"'; - #access_log /var/log/nginx/access.log main; - access_log off; + access_log ; # server configuration options server_tokens off; diff --git a/build/entrypoint.sh b/build/entrypoint.sh index b097dea..23ba40d 100755 --- a/build/entrypoint.sh +++ b/build/entrypoint.sh @@ -10,6 +10,17 @@ printf "\nUpdating server name list... " sed -i -e "s%%${SERVER_NAMES}%" /etc/nginx/server_names.conf printf "done\n" +# update access log global preference +if [ "$ACCESS_LOG" = "OFF" ]; then + printf "Turning access log OFF..." + sed -i -e "s%%OFF%" /etc/nginx/nginx.conf + printf "done\n" +elif [ "$ACCESS_LOG" = "ON" ]; then + printf "Turning access log ON..." + sed -i -e "s%%/var/log/nginx/access.log combined%" /etc/nginx/nginx.conf + printf "done\n" +fi + # update HTTPS redirect port if SSL server test block exists if [ -f "/etc/nginx/sites/note" ]; then printf "\nUpdating port redirects...\n"