web-dev-qa-db-ja.com

dockerのスーパーバイザーを使用してnginxアクセスログを無効にする

Docker stdoutで出力するnginxからのアクセスログを無効にできないようです(docker logs <container>

これは私のDockerfileです

FROM php:7.3.11-fpm-Alpine as base

WORKDIR /var/www

# Use the default production configuration
RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

#Â Install dependencies
RUN set -xe \
    && apk add --no-cache bash icu-dev  \
    && apk add --no-cache nginx supervisor curl

# Configure nginx
COPY nginx.conf /etc/nginx/nginx.conf

# Configure supervisord
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Make sure files/folders needed by the processes are accessable when they run under the nobody user
RUN chown -R nobody.nobody /run && \
  chown -R nobody.nobody /var/lib/nginx && \
  chown -R nobody.nobody /var/tmp/nginx && \
  chown -R nobody.nobody /var/log/nginx

# Setup document root
RUN mkdir -p /var/www/html/public

WORKDIR /var/www/html

RUN echo "<?php echo 'OK';" >> /var/www/html/public/healthcheck.php

USER nobody

# Expose the port nginx is reachable on
EXPOSE 8080

# Let supervisord start nginx & php-fpm
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

これはnginx.confです

worker_processes  1;
pid /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log off;

    proxy_buffers 16 16k;
    proxy_buffer_size 16k;

    keepalive_timeout  65;

    server {
        listen [::]:8080 default_server;
        listen 8080 default_server;
        server_name _;

        sendfile off;

        root /var/www/html/public;
        index index.php index.html;

        location = /healthcheck.php {
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
                    fastcgi_pass 127.0.0.1:9000;
        }

    }
}

これはsupervisord.confです

[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
pidfile=/run/supervisord.pid

[program:php-fpm]
command=php-fpm -F
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=false
startretries=0

[program:nginx]
command=nginx -g 'daemon off;'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=false
startretries=0

しかし、まだ出力したくない

2019-12-16 11:04:30,107 INFO supervisord started with pid 1
2019-12-16 11:04:31,110 INFO spawned: 'nginx' with pid 7
2019-12-16 11:04:31,122 INFO spawned: 'php-fpm' with pid 8
[16-Dec-2019 11:04:31] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[16-Dec-2019 11:04:31] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[16-Dec-2019 11:04:31] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[16-Dec-2019 11:04:31] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[16-Dec-2019 11:04:31] NOTICE: fpm is running, pid 8
[16-Dec-2019 11:04:31] NOTICE: ready to handle connections
2019-12-16 11:04:32,209 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2019-12-16 11:04:32,211 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
127.0.0.1 -  16/Dec/2019:11:04:34 +0000 "GET /healthcheck.php" 200
127.0.0.1 -  16/Dec/2019:11:04:34 +0000 "GET /healthcheck.php" 200
127.0.0.1 -  16/Dec/2019:11:04:34 +0000 "GET /healthcheck.php" 200

Dockerとスーパーバイザーを使用してnginxアクセスログを無効にするにはどうすればよいですか?

1
Manse

私は何が問題であるかを理解することができました-それらのリクエストを記録していたのはphp-fpmのアクセスログであり、まったくnginxはまったく記録していませんでした。 supervisordでデバッグログを有効にしたものをログに記録しているものを見つけるために、以下の出力が得られました

2020-01-06 11:57:27,790 DEBG 'php-fpm' stderr output:
127.0.0.1 -  06/Jan/2020:11:57:27 +0000 "GET /healthcheck.php" 200

2020-01-06 11:57:27,790 DEBG 'php-fpm' stderr output:
127.0.0.1 -  06/Jan/2020:11:57:27 +0000 "GET /healthcheck.php" 200

2020-01-06 11:57:27,792 DEBG 'nginx' stdout output:
172.17.0.1 - - [06/Jan/2020:11:57:27 +0000] "GET /healthcheck.php HTTP/1.1" 200 12 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0" "-"

2020-01-06 11:57:27,792 DEBG 'nginx' stdout output:
172.17.0.1 - - [06/Jan/2020:11:57:27 +0000] "GET /healthcheck.php HTTP/1.1" 200 12 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0" "-"

次に、構成を更新し(デフォルトではphp-fpm docker imageがアクセスログをstdoutに出力するため)、nginxの構成が期待どおりに機能し始めました

0
Manse