我不断在我的 Kubernetes 集群中看到如下日志:
[php] - - 05/Jul/2020:20:15:55 +0000 "POST /api/bookings" 200
我怎样才能禁用它们?
如果 PHP 想要写入错误或其他内容,我希望保留它,这只是我不关心的请求日志(无论如何,NGINX 都会第二次记录它们)。
我在用着php:7.1-fpm
答案1
它依赖于 Linux 发行版,例如在 CentOS 上,您可以在目录中找到配置文件,并通过编辑几个变量(如、、甚至更多(取决于 php 版本))来/etc/php-fpm.d
禁用日志记录。access.log
php_admin_flag[log_errors]
答案2
放
access.log = /dev/null
在你的 php-fpm conf 文件中。在我的例子中/etc/php-fpm.d/www.conf
或者对于 docker 文件:
RUN echo "access.log = /dev/null" >> /usr/local/etc/php-fpm.d/www.conf
答案3
谢谢您的帮助,但我需要做得更好。
在docker容器中我在几个地方发现了access.log。
root@8f03d2e7056f:/var/www/html# grep -r 'access.log' /usr/local/etc/
/usr/local/etc/php-fpm.d/www.conf.default:; - 'access.log'
/usr/local/etc/php-fpm.d/www.conf.default:; The access log file
/usr/local/etc/php-fpm.d/www.conf.default:;access.log = log/$pool.access.log
/usr/local/etc/php-fpm.d/www.conf.default:; The access log format.
/usr/local/etc/php-fpm.d/docker.conf:access.log = /proc/self/fd/2
/usr/local/etc/php-fpm.d/www.conf:; - 'access.log'
/usr/local/etc/php-fpm.d/www.conf:; The access log file
/usr/local/etc/php-fpm.d/www.conf:;access.log = log/$pool.access.log
/usr/local/etc/php-fpm.d/www.conf:; The access log format.
root@8f03d2e7056f:/var/www/html#
我对 docker.conf 文件特别感兴趣
root@8f03d2e7056f:/var/www/html# cat /usr/local/etc/php-fpm.d/docker.conf
[global]
error_log = /proc/self/fd/2
; https://github.com/docker-library/php/pull/725#issuecomment-443540114
log_limit = 8192
[www]
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2
clear_env = no
; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
decorate_workers_output = no
root@8f03d2e7056f:/var/www/html#
结果是 dockerfile 中的一行
RUN sed -i 's/access.log = \/proc\/self\/fd\/2/access.log = \/proc\/self\/fd\/1/g' /usr/local/etc/php-fpm.d/docker.conf
祝你好运