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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PHP5-FPM如何向nginx发送错误?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试使用PHP-FPMNginx中的错误记录,因为我在网上找不到任何好的解释.大多数指南说如果我想将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文件.那里可能存在冲突.

脚本宝典总结

以上是脚本宝典为你收集整理的PHP5-FPM如何向nginx发送错误?全部内容,希望文章能够帮你解决PHP5-FPM如何向nginx发送错误?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。