Set 'logrotate' for 'nginx' logs (#2111)

* Update Dockerfile

Install 'logrotate' for nginx log. Issue https://github.com/laradock/laradock/issues/1357

* Create nginx

Create 'logrotate' file for nginx log. Issue https://github.com/laradock/laradock/issues/1357

* Update Dockerfile

Copy 'logrotate' config file. Issue https://github.com/laradock/laradock/issues/1357

* Update nginx

Add 'nodateext' logrotate option to archive with sequence number

* Update startup.sh

Add line to start 'crond' demon

* Update nginx

Update permissions
This commit is contained in:
vlauciani 2019-05-18 04:54:45 +02:00 committed by Shao Yu-Lung (Allen)
parent 76b71d264d
commit 7ea44ca25a
3 changed files with 25 additions and 0 deletions

View File

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

14
nginx/logrotate/nginx Normal file
View File

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

View File

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