Skip to content

Commit

Permalink
Fix issues with log rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Weiyan Shao committed Jun 19, 2020
1 parent 0c30559 commit a945324
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/*

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions fs_overlay/var/lib/nginx-conf/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down

0 comments on commit a945324

Please sign in to comment.