diff --git a/Dockerfile b/Dockerfile index 4744988..6328871 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,7 @@ ARG ARCH=amd64 # Delete sym links from nginx image, install logrotate RUN rm /var/log/nginx/access.log && \ - rm /var/log/nginx/error.log && \ - apt-get update && \ - apt-get -y install logrotate + rm /var/log/nginx/error.log WORKDIR /root @@ -24,7 +22,7 @@ RUN tar xzf /tmp/s6-overlay-$ARCH.tar.gz -C / &&\ rm /tmp/s6-overlay-$ARCH.tar.gz && \ rm /etc/nginx/conf.d/default.conf && \ apt-get update && \ - apt-get install -y python ruby cron iproute2 apache2-utils && \ + apt-get install -y python ruby cron iproute2 apache2-utils logrotate && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index f03d3e3..c94fa1f 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ For valid IP values see [Nginx allow](http://nginx.org/en/docs/http/ngx_http_acc ### Logging configuration -By default no Nginx logs are written. There are few options to set them up: +By default no Nginx access logs are written, and error logs are written to stdout, which will be captured by Docker. There are few options to configure them: * Redirect error/access logs to stdout/stderr: @@ -411,6 +411,13 @@ By default no Nginx logs are written. There are few options to set them up: If you want to alter log rotation configuration, you can overwrite `/etc/logrotate.d/nginx`. + There are other configurable environment variables: + + ``` + `ACCESS_LOG_BUFFER` - controls buffer size of access log. Example: 16k. + `ERROR_LOG_LEVEL` - controls error log level. Default value is `error` + ``` + * Write logs to custom locations: ```yaml diff --git a/fs_overlay/var/lib/nginx-conf/nginx.conf.erb b/fs_overlay/var/lib/nginx-conf/nginx.conf.erb index 11ea223..cc8af8f 100644 --- a/fs_overlay/var/lib/nginx-conf/nginx.conf.erb +++ b/fs_overlay/var/lib/nginx-conf/nginx.conf.erb @@ -31,28 +31,24 @@ http { } <% end %> - <% if ENV['ACCESS_LOG'] == 'off' || ENV['ACCESS_LOG'] == '' %> + <% if !ENV['ACCESS_LOG'] || ENV['ACCESS_LOG'] == '' || ENV['ACCESS_LOG'] == 'off' %> access_log off; <% elsif ENV['ACCESS_LOG'] == 'stdout' %> - access_log /dev/stdout main buffer=<%= ENV['ACCESS_LOG_BUFFER'] || "16k" %>; - <% else %> + access_log /dev/stdout main <%= ENV['ACCESS_LOG_BUFFER'] && "buffer=#{ENV['ACCESS_LOG_BUFFER']}" %>; <% elsif ENV['ACCESS_LOG'] == 'stderr' %> - access_log /dev/stderr main buffer=<%= ENV['ACCESS_LOG_BUFFER'] || "16k" %>; - <% else %> + access_log /dev/stderr main <%= ENV['ACCESS_LOG_BUFFER'] && "buffer=#{ENV['ACCESS_LOG_BUFFER']}" %>; <% elsif ENV['ACCESS_LOG'] == 'default' %> - access_log /var/log/nginx/access.log main buffer=<%= ENV['ACCESS_LOG_BUFFER'] || "16k" %>; + access_log /var/log/nginx/access.log main <%= ENV['ACCESS_LOG_BUFFER'] && "buffer=#{ENV['ACCESS_LOG_BUFFER']}" %>; <% else %> - access_log <%= ENV['ACCESS_LOG'] %> main buffer=<%= ENV['ACCESS_LOG_BUFFER'] || "16k" %>; + access_log <%= ENV['ACCESS_LOG'] %> main <%= ENV['ACCESS_LOG_BUFFER'] && "buffer=#{ENV['ACCESS_LOG_BUFFER']}" %>; <% end %> - <% if ENV['ERROR_LOG'] == 'off' || ENV['ERROR_LOG'] == '' %> + <% if !ENV['ERROR_LOG'] || ENV['ERROR_LOG'] == '' || ENV['ERROR_LOG'] == 'stderr' %> + error_log /dev/stderr <%= ENV['ERROR_LOG_LEVEL'] || "error" %>; + <% elsif ENV['ERROR_LOG'] == 'off' %> error_log off; <% elsif ENV['ERROR_LOG'] == 'stdout' %> error_log /dev/stdout <%= ENV['ERROR_LOG_LEVEL'] || "error" %>; - <% else %> - <% elsif ENV['ERROR_LOG'] == 'stderr' %> - error_log /dev/stderr <%= ENV['ERROR_LOG_LEVEL'] || "error" %>; - <% else %> <% elsif ENV['ERROR_LOG'] == 'default' %> error_log /var/log/nginx/error.log <%= ENV['ERROR_LOG_LEVEL'] || "error" %>; <% else %>