调试著名的-在stderr中发送的FastCGI:“主脚本未知";从上游读取响应头时 [英] Debugging the famous - FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

查看:423
本文介绍了调试著名的-在stderr中发送的FastCGI:“主脚本未知";从上游读取响应头时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SO有很多文章提到了此错误代码:

SO has many articles mentioning this error code:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream...

这可能意味着此错误消息或多或少是无用的.

That probably means that this error message is more or less useless.

该消息告诉我们,由于某些原因,FastCGI处理程序不喜欢发送的任何内容.问题是有时我们不知道原因是什么.

The message is telling us that the FastCGI handler doesn't like whatever it was sent for some reason. The problem is that sometimes we have no idea what the reason is.

所以我要重新陈述一个问题-我们如何 调试 该错误代码?

So I'm re-stating the question -- How do we debug this error code?

考虑一下我们拥有一个非常简单的站点(仅包含phpinfo.php文件)的情况.此外,还有一个非常简单的nginx配置,如下所示:

Consider the situation where we have a very simple site, with just the phpinfo.php file. Additionally, there is a very simple nginx config, as follows:

server {
    server_name testsite.local;

    root /var/local/mysite/;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  fastcgi_backend;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

我们如何才能准确地看到输出/记录发送到脚本的fastcgi_params是什么?

我们如何看到实际的错误消息?就我而言,我使用的是php-fpm.它在日志中没有有关此错误的信息.日志不会为该错误追加任何行. php-fpm是否有详细模式?

How can we see the actual error message? In my case, I'm using php-fpm. It has no info in the log about this error. The logs do not append any rows for this error. Is there a verbose mode for php-fpm?

/var/log/php-fpm/error.log
/var/log/php-fpm/www-error.log

我试图在php-fpm.conf文件中设置它

I've tried to set this in the php-fpm.conf file

log_level = notice

,并且在php-fpm.d/www.conf文件中:

and this in the php-fpm.d/www.conf file:

catch_workers_output = yes

推荐答案

要回答您的问题:

  1. 在php-fpm.d/www.conf文件中:

设置access.log条目:

set the access.log entry:

access.log = /var/log/$pool.access.log

  1. 重新启动php-fpm服务.

  1. restart php-fpm service.

尝试访问您的页面

cat/var/log/www.access.log,您将看到如下访问日志:

cat /var/log/www.access.log, you will see access logs like:

- - 10/Nov/2016:19:02:11 +0000 "GET /app.php" 404 - - 10/Nov/2016:19:02:37 +0000 "GET /app.php" 404

- - 10/Nov/2016:19:02:11 +0000 "GET /app.php" 404 - - 10/Nov/2016:19:02:37 +0000 "GET /app.php" 404

  • 如果看到的"GET/"没有正确的php文件名,则是您的nginx conf问题.

  • if you see "GET /" without a correct php file name, then it's your nginx conf problem.

如果看到带有404的"GET/app.php",则表明nginx正确传递了脚本文件名,但php-fpm无法访问此文件(用户"php-fpm:php-fpm" don无法访问您的文件,这使我困了3个小时)

if you see "GET /app.php" with 404, it means nginx is correctly passing the script file name but php-fpm failed to access this file (user "php-fpm:php-fpm" don't have access to your file, which trapped me for 3 hours)

希望我的回答有帮助.

这篇关于调试著名的-在stderr中发送的FastCGI:“主脚本未知";从上游读取响应头时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆