简体   繁体   English

如何在 docker 容器中启用 php-fpm 的访问日志?

[英]How to enable access log for php-fpm in docker container?

Note: I am NOT talking about nginx' own access log.注意:我不是在谈论 nginx 自己的访问日志。 That one works fine.那个很好用。 This questions is about enabling the php-fpm access.log .这个问题是关于启用 php-fpm access.log的。


Currently, I am trying to debug the FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream error目前,我正在尝试调试在 stderr 中发送的 FastCGI:“Primary script unknown”,同时从上游错误读取响应 header

One proposed option is to set the access.log entry in the php-fpm.d/www.conf .一种建议的选项是在php-fpm.d/www.conf中设置 access.log 条目。

access.log = /var/log/$pool.access.log

Now, I have a docker stack and my php-fpm container is build from the php:7.3-fpm-alpine image.现在,我有一个 docker 堆栈,我的 php-fpm 容器是从php:7.3-fpm-alpine图像构建的。

While I have figured out that it stores its php config files at:虽然我发现它将其 php 配置文件存储在:

/usr/local/etc/php

and I also found the www.conf at:我还在以下位置找到了www.conf

/usr/local/etc/php-fpm.d/www.conf

So in a local file I add the default content as provided by the image and add at the end:因此,在本地文件中,我添加了图像提供的默认内容并在最后添加:

php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
access.log = /var/log/$pool.access.log

and I copy that file during build into the docker container.我在构建过程中将该文件复制到 docker 容器中。

COPY ./.docker/php/www.conf /usr/local/etc/php-fpm.d/www.conf

Yet when I try to access my server, I don't see any log file being created on incoming requests.然而,当我尝试访问我的服务器时,我没有看到在传入请求中创建任何日志文件。

What am I missing to activate the php-fpm access log?我缺少什么来激活 php-fpm 访问日志? How can I figure out why I don't see any log?我怎样才能弄清楚为什么我没有看到任何日志?

The way to do this is to send the error and the access logs to the following address:这样做的方法是将错误和访问日志发送到以下地址:

/proc/self/fd/2

So replace the "file" locations like so:因此,像这样替换“文件”位置:

access.log = /proc/self/fd/2
error_log = /proc/self/fd/2

Then you should be able to inspect the fpm-logs with docker logs [container-id]然后您应该能够使用docker logs [container-id]检查 fpm-logs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM