PHP5-FPM gửi lỗi đến nginx như thế nào?


9

Tôi đã thử nghiệm một chút với việc đăng nhập lỗi trong php-fpm và nginx vì tôi không thể tìm thấy bất kỳ lời giải thích tốt nào trên web. Hầu hết các hướng dẫn đều nói tôi nên đổi catch_workers_outputthành yesnếu tôi muốn gửi lỗi từ php5-fpm trở lại nginx. Tuy nhiên, trong các thử nghiệm của tôi, tôi thấy rằng ngay cả khi catch_workers_outputđược đặt thành no, lỗi vẫn được nginx ghi lại đúng cách.

Đây là cấu hình virtualhost của tôi:

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;
        }
}

Đây là những phát hiện của tôi:

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

Câu hỏi của tôi là làm thế nào để PHP5-FPM gửi nhật ký lỗi đến nginx ngay cả khi không có đầu ra stderr (khi nào catch_workers_output=no) từ php-fpm? Tôi không thể tìm thấy nó được ghi lại ở bất cứ đâu.

Câu trả lời:


1

Khi cấu hình nginx của bạn sử dụng php_admin_value , php_admin_flag và php_flag, đó là ghi đè các giá trị trong php.ini. Nhận xét các cài đặt nginx sẽ để lại tệp php.ini.

Hãy xem trong file php.ini ở các cài đặt cho display_errors , display_startup_errors , error_reporting , html_errors và log_errors . Có lẽ có một cuộc xung đột ở đó.

Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookie và Chính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.