首页 > 解决方案 > 主管 + Nginx + PHP-FPM 不重定向标准错误

问题描述

我有一个带有 supervistord、nginx 和 PHP-FPM 的 docker 映像设置。日志记录是使用 awslogs 驱动程序完成的。一些 PHP 致命错误会像写入文件时被拒绝的权限一样进入 awslogs。来自 supervisord、nginx 和 PHP-FPM 的所有错误日志都发送到 /dev/stderr,但它们不会出现在 awslogs 中。如果我将 PHP-FPM 配置中的 error_log 配置到文件中,则会写入致命错误。

应该怎么做才能将标准错误从 PHP-FPM “转发”到 Nginx 或 Supervisord?

监督配置:

[unix_http_server]
file=/dev/shm/supervisor.sock   ; (the path to the socket file)

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
user=root            ;

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock ; use a unix:// URL  for a unix socket

[program:php-fpm]
command = /usr/local/sbin/php-fpm --nodaemonize --fpm-config /usr/local/etc/php-fpm.d/www.conf
autostart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
;stderr_logfile=/dev/stderr
redirect_stderr=true
stderr_logfile_maxbytes=0

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
;stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
redirect_stderr=true
stopsignal=QUIT

[include]
files = /etc/supervisor/conf.d/*.conf

Nginx 配置:

server {
listen   80; ## listen for ipv4; this line is default and implied
listen   [::]:80 default ipv6only=on; ## listen for ipv6

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

# Make site accessible from http://localhost/
server_name _;

# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;

# Add stdout logging
error_log /dev/stderr;
access_log /dev/stdout;

....
}

我一直在努力,因为很多小时和谷歌搜索,但什么都没有......

标签: phpnginxsupervisordstderr

解决方案


推荐阅读