php 调试著名的 - 在 stderr 中发送的 FastCGI: "Primary script unknown" while reading response header from upstream

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35261922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:24:52  来源:igfitidea点击:

Debugging the famous - FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

phpnginx

提问by 010110110101

SO has many articles mentioning this error code:

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

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.

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

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.

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

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

所以我重新提出这个问题——我们如何调试这个错误代码?

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:

考虑我们有一个非常简单的站点,只有 phpinfo.php 文件的情况。此外,还有一个非常简单的 nginx 配置,如下:

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

How can we see output/log exactly what fastcgi_params got sent to the script?

我们如何才能准确地看到发送到脚本的 fastcgi_params 的输出/日志?

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?

我们如何才能看到实际的错误信息?就我而言,我使用的是 php-fpm。日志中没有关于此错误的信息。日志不会为此错误附加任何行。php-fpm 有详细模式吗?

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

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

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

log_level = notice

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

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

catch_workers_output = yes

回答by Shengjie YU

To answer your question:

回答你的问题:

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

set the access.log entry:

设置 access.log 条目:

access.log = /var/log/$pool.access.log
  1. restart php-fpm service.

  2. try to access your page

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

  1. 重启 php-fpm 服务。

  2. 尝试访问您的页面

  3. cat /var/log/www.access.log,你会看到如下访问日志:

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

To resolve "Primary script unknown" problem:

要解决“主脚本未知”问题:

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

  • 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)

  • 如果您看到“GET /”没有正确的 php 文件名,那么这是您的 nginx conf 问题。

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

Hope my answer helps.

希望我的回答有帮助。

回答by ?smail Atkurt

For MacOs users, in case if someone encountered as in my situation:

对于 MacOs 用户,如果有人遇到我的情况:

I had started php service with:

我已经开始了 php 服务:

sudo brew start php72

since I have used "sudo" permissions was different. I needed to stop and start php service without sudo.

因为我使用过“sudo”权限是不同的。我需要在没有 sudo 的情况下停止和启动 php 服务。

sudo brew stop php72
brew start php72

Hope helps to someone.

希望对某人有帮助。

回答by herbertD

Check the root's position and also the file existence under it, I met this error because of the Root path TYPO.

检查root的位置以及它下面的文件是否存在,由于Root 路径 TYPO,我遇到了这个错误。