add option to turn on access log

This commit is contained in:
Asif Bacchus 2019-10-18 01:53:20 -06:00
parent d6e49f4d09
commit bfdb85b384
4 changed files with 19 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <ACCESS_LOG_SETTING>;
# server configuration options
server_tokens off;

View File

@ -10,6 +10,17 @@ printf "\nUpdating server name list... "
sed -i -e "s%<SERVER_NAMES>%${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%<ACCESS_LOG_SETTING>%OFF%" /etc/nginx/nginx.conf
printf "done\n"
elif [ "$ACCESS_LOG" = "ON" ]; then
printf "Turning access log ON..."
sed -i -e "s%<ACCESS_LOG_SETTING>%/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"