【发布时间】:2022-02-17 04:22:37
【问题描述】:
我最近一直在尝试从 PHP 应用程序中本地基于文件的日志记录转移到通过标准输出推送 PHP 错误,以便它们与 docker 设置中的其他日志一起输出,并遵循已建立的原则 @987654321 @ 。这很好用,如果您将error_log 位置设置为/dev/stdout,那么我会通过拖尾 docker 日志看到来自 PHP 的错误。但是,同样的错误也会出现在 nginx 容器中,如下通过“FastCGI sent in stderr”:
docker-compose-nginx-phpfpm-php-fpm-1 | NOTICE: PHP message: test
docker-compose-nginx-phpfpm-php-fpm-1 | 172.18.0.3 - 18/Jan/2022:20:00:20 +0000 "GET /index.php" 200
docker-compose-nginx-phpfpm-web-1 | 2022/01/18 20:00:20 [error] 32#32: *18 FastCGI sent in stderr: "PHP message: test" while reading response header from upstream, client: 172.18.0.1, server: phpfpm.local, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.2:9000", host: "localhost:8080"
为了清楚起见:
PHP 容器日志
docker-compose-nginx-phpfpm-php-fpm-1 | NOTICE: PHP message: test
Nginx 容器日志
docker-compose-nginx-phpfpm-web-1 | 2022/01/18 20:00:20 [error] 32#32: *18 FastCGI sent in stderr: "PHP message: test" while reading response header from upstream, client: 172.18.0.1, server: phpfpm.local, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.2:9000", host: "localhost:8080"
这里发生了什么?这是预期的行为吗?
这是一个非常基本和标准的 php-fpm/nginx 设置的结果,带有 docker-compose.yml,如下所示:
version: "3.9"
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php-fpm
php-fpm:
image: php:8-fpm
volumes:
- ./src:/var/www/html
一个 default.conf 像:
server {
index index.php index.html;
server_name phpfpm.local;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
还有一个 index.php,例如:
<?php
ini_set('display_errors', 'off');
ini_set('error_log', '/dev/stdout');
error_log('test');
echo phpinfo();
【问题讨论】: