diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 12c456d8..c98498f3 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -14,6 +14,7 @@ RUN if [ ${CHANGE_SOURCE} = true ]; then \ RUN apk update \ && apk upgrade \ + && apk --update add logrotate \ && apk add --no-cache openssl \ && apk add --no-cache bash \ && adduser -D -H -u 1000 -s /bin/bash www-data @@ -21,6 +22,12 @@ RUN apk update \ ARG PHP_UPSTREAM_CONTAINER=php-fpm ARG PHP_UPSTREAM_PORT=9000 +# Create 'messages' file used from 'logrotate' +RUN touch /var/log/messages + +# Copy 'logrotate' config file +COPY logrotate/nginx /etc/logrotate.d/ + # Set upstream conf and remove the default conf RUN echo "upstream php-upstream { server ${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT}; }" > /etc/nginx/conf.d/upstream.conf \ && rm /etc/nginx/conf.d/default.conf diff --git a/nginx/logrotate/nginx b/nginx/logrotate/nginx new file mode 100644 index 00000000..8c89a83a --- /dev/null +++ b/nginx/logrotate/nginx @@ -0,0 +1,14 @@ +/var/log/nginx/*.log { + daily + missingok + rotate 32 + compress + delaycompress + nodateext + notifempty + create 644 www-data root + sharedscripts + postrotate + [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid` + endscript +} diff --git a/nginx/startup.sh b/nginx/startup.sh index 069d1418..f8e7b229 100644 --- a/nginx/startup.sh +++ b/nginx/startup.sh @@ -6,4 +6,8 @@ if [ ! -f /etc/nginx/ssl/default.crt ]; then openssl x509 -req -days 365 -in "/etc/nginx/ssl/default.csr" -signkey "/etc/nginx/ssl/default.key" -out "/etc/nginx/ssl/default.crt" fi +# Start crond in background +crond -l 2 -b + +# Start nginx in foreground nginx