加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP5-FPM如何向nginx发送错误?

发布时间:2020-12-13 13:59:28 所属栏目:PHP教程 来源:网络整理
导读:我一直在尝试使用php-fpm和nginx中的错误记录,因为我在网上找不到任何好的解释.大多数指南说如果我想将php5-fpm中的错误发送回nginx,我应该将catch_workers_output更改为yes.但是,在我的实验中,我发现即使将catch_workers_output设置为no,nginx仍会正确记录
我一直在尝试使用php-fpm和nginx中的错误记录,因为我在网上找不到任何好的解释.大多数指南说如果我想将php5-fpm中的错误发送回nginx,我应该将catch_workers_output更改为yes.但是,在我的实验中,我发现即使将catch_workers_output设置为no,nginx仍会正确记录错误.

这是我的virtualhost配置:

server {                                                                                                                                                                                                                                 
        server_name     domain.com;
        return  301 http://www.domain.com$request_uri;
        access_log off;
}

server {
        listen 80;
        listen [::]:80;

        root /home/websites/domain.com;
        index index.php index.html index.htm;


        error_log /home/websites/logs/domain.com/error.log warn;
        access_log /home/websites/logs/domain.com/access.log;

        #switch on gzip
        gzip on;
        gzip_min_length  1100;
        gzip_buffers  10 32k;
        gzip_types    text/plain application/x-javascript text/xml text/css;
        gzip_vary on;


        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        location ~* .(gif|jpg|jpeg|png|css|js|ico)${
                expires 30d;
                access_log off;
        }

        error_page 404 /404.html;

        location ~ .php${
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                # With php5-cgi alone:
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        # deny access to .htaccess files,if Apache's document root
        # concurs with nginx's one
        location ~ /.ht {
                deny all;
        }
}

以下是我的发现:

Exp 1
        poolconf:
                ; catch_workers_output = no (commented out)
                php_admin_value[error_log] = /var/log/fpm-php.www.log
                php_admin_flag[log_errors] = on
                ; php_flag[display_errors] = 0

        result:
                errors not shown in browser
                error written in /var/log/fpm-php.www.log
                error not written in virtualhost error-log in nginx
                errors not displayed in stderr when running php5-fpm non-daemonized

Exp 2
        poolconf:
                catch_workers_output = yes
                php_admin_value[error_log] = /var/log/fpm-php.www.log
                php_admin_flag[log_errors] = on
                php_flag[display_errors] = 0

        results:
                no error in browser
                error written in /var/log/fpm-php.www.log
                error not written to virtualhost error-log by nginx
                errors not displayed in stderr when running php5-fpm non-daemonized

Exp 3
        poolconf:
                catch_workers_output = yes
                ; php_admin_value[error_log] = /var/log/fpm-php.www.log
                ; php_admin_flag[log_errors] = on
                php_flag[display_errors] = 0

        results:
                no errors in browser
                error  NOT written in /var/log/fpm-php.www.log
                error WRITTEN to virtualhost error-log by nginx
                errors DISPLAYED in stderr when running php5-fpm non-daemonized

Exp 4
        poolconf:
                ; catch_workers_output = no (commented out)
                ; php_admin_value[error_log] = /var/log/fpm-php.www.log
                ; php_admin_flag[log_errors] = on
                php_flag[display_errors] = 0

        results:
                no errors in browser
                error NOT written in /var/log/fpm-php.www.log
                error WRITTEN to virtualhost error-log by nginx
                errors NOT displayed in stderr when running php5-fpm non-daemonized

我的问题是PHP5-FPM如何将错误日志发送到nginx,即使php-fpm没有stderr输出(当catch_workers_output = no时)?我无法在任何地方找到它.

当你的nginx配置使用php_admin_value,php_admin_flag和php_flag时,它会覆盖php.ini中的值.注释掉nginx设置会让php.ini文件负责.

在display_errors,display_startup_errors,error_reporting,html_errors和log_errors的设置中查看php.ini文件.那里可能存在冲突.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读