php 1 FastCGI 在 stderr 中发送:“主脚本未知”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17194196/
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-25 12:27:46  来源:igfitidea点击:

1 FastCGI sent in stderr: "Primary script unknown"

phpnginx

提问by We0

My first time using Nginx, but I am more than familiar with Apache and Linux. I am using an existing project and when ever I am trying to see the index.php I get a 404 File not found.

我第一次使用 Nginx,但我对 Apache 和 Linux 非常熟悉。我正在使用一个现有的项目,当我试图查看 index.php 时,我得到一个 404 文件未找到。

Here is the access.log entry:

这是 access.log 条目:

2013/06/19 16:23:23 [error] 2216#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.ordercloud.lh"

And here is the sites-available file:

这是网站可用的文件:

server {
# Listening on port 80 without an IP address is only recommended if you are not running multiple v-hosts
    listen       80;
# Bind to the public IP bound to your domain
#listen 127.0.0.11:80;
# Specify this vhost's domain name
    server_name www.ordercloud.lh;
    root /home/willem/git/console/frontend/www;
    index index.php index.html index.htm;

# Specify log locations for current site
    access_log /var/log/access.log;
    error_log /var/log/error.log warn;

# Typically I create a restrictions.conf file that I then include across all of my vhosts
#include conf.d/restrictions.conf;
# I've included the content of my restrictions.conf in-line for this example

# BEGIN restrictions.conf
# Disable logging for favicon
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

# Disable logging for robots.txt
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
# END restrictions.conf

# Typically I create a yiiframework.conf file that I then include across all of my yii vhosts
#include conf.d/yiiframework.conf;
# I've included the content of my yiiframework.conf in-line for this example

# BEGIN yiiframework.conf
# Block access to protected, framework, and nbproject (artifact from Netbeans)
    location ~ /(protected|framework|nbproject) {
        deny all;
        access_log off;
        log_not_found off;
    }

# Block access to theme-folder views directories
    location ~ /themes/\w+/views {
        deny all;
        access_log off;
        log_not_found off;
    }

# Attempt the uri, uri+/, then fall back to yii's index.php with args included
# Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
# END yiiframework.conf

# Tell browser to cache image files for 24 hours, do not log missing images
# I typically keep this after the yii rules, so that there is no conflict with content served by Yii
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 24h;
        log_not_found off;
    }

# Block for processing PHP files
# Specifically matches URIs ending in .php
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_intercept_errors on;
# Fix for server variables that behave differently under nginx/php-fpm than typically expected
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Include the standard fastcgi_params file included with nginx
        include fastcgi_params;
        #fastcgi_param  PATH_INFO        $fastcgi_path_info;
        #fastcgi_index index.php;
# Override the SCRIPT_FILENAME variable set by fastcgi_params
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
# Pass to upstream PHP-FPM; This must match whatever you name your upstream connection
        fastcgi_pass 127.0.0.1:9000;

    }
}

My /home/willem/git/consoleis owned by www-data:www-data (my web user running php etc) and I have given it 777 permissions out of frustration...

/home/willem/git/console的归 www-data:www-data(我的网络用户运行 php 等)所有,出于沮丧,我给了它 777 权限......

Can anybody advise?

有人可以建议吗?

采纳答案by We0

Ok, so 3 things I found after a day of struggling

好的,经过一天的努力,我发现了 3 件事

  1. For some reason I had already something running on port 9000 so I changed to 9001
  2. My default site was intercepting my new one, once again I don't under stand why since it shouldn't, but I just unlinked it
  3. Nginx doesn't automatically do the sym link for sites-available to site-enabled.
  1. 出于某种原因,我已经在端口 9000 上运行了一些东西,所以我更改为 9001
  2. 我的默认站点拦截了我的新站点,我再次不明白为什么,因为它不应该,但我只是取消了它的链接
  3. Nginx 不会自动为启用站点的站点提供符号链接。

Hope this saves someone some trouble!

希望这可以为某人节省一些麻烦!

Here is a more detailed link in server fault: https://serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown/517207#517207

这是服务器故障中更详细的链接:https: //serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown/517207#517207

回答by Sergey Bogdanov

That message from the fastcgi server usually means that the SCRIPT_FILENAME that it was given was not found or inaccessible as a file on its filesystem.

来自 fastcgi 服务器的消息通常意味着它被提供的 SCRIPT_FILENAME 在其文件系统上没有找到或无法作为文件访问。

Checkout file permissions on /home/willem/git/console/frontend/www/index.php

在 /home/willem/git/console/frontend/www/index.php 上签出文件权限

Is it 644?

是644吗?

And /home/willem/git/console/frontend/www/

和 /home/willem/git/console/frontend/www/

Is it 755?

是755吗?

回答by flower_green

In case anyone had the same error: in my case the problem was the missing root directive inside the location block in nginx.conf, as explained in the Arch wiki

如果有人有同样的错误:就我而言,问题是 nginx.conf 中的 location 块中缺少 root 指令,如 Arch wiki 中所述

回答by PLA

"Primary script unknown"is caused by SELinux security context.

“主脚本未知”是由SELinux 安全上下文引起的

client get the response

客户端得到响应

File not found.

文件未找到。

nginx error.log has the following error message

nginx error.log 有以下错误信息

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

*19 FastCGI 在 stderr 中发送:从上游读取响应头时“主脚本未知”

so just change security context type of web root folder to httpd_sys_content_t

所以只需将 Web 根文件夹的安全上下文类型更改为httpd_sys_content_t

chcon -R -t httpd_sys_content_t /var/www/show

chcon -R -t httpd_sys_content_t /var/www/show




there are 3 users for nginx/php-fpm config




nginx/php-fpm 配置有 3 个用户

/etc/nginx/nginx.conf

/etc/nginx/nginx.conf

user nobody nobody;  ### `user-1`, this is the user run nginx woker process
...
include servers/*.conf;

/etc/nginx/servers/www.conf

/etc/nginx/servers/www.conf

location ~ \.php$ {
#   fastcgi_pass 127.0.0.1:9000;  # tcp socket
    fastcgi_pass unix:/var/run/php-fpm/fpm-www.sock;  # unix socket
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

/etc/php-fpm.d/www.conf

/etc/php-fpm.d/www.conf

[www]
user = apache  ### `user-2`, this is the user run php-fpm pool process
user = apache

;listen = 127.0.0.1:9000  # tcp socket
listen = /var/run/php-fpm/fpm-www.sock  # unix socket

listen.onwer = nobody  ### `user-3`, this is the user for unix socket, like /var/run/php-fpm/fpm-www.sock
listen.group = nobody  # for tcp socket, these lines can be commented
listen.mode = 0660

user-1 and user-2 is not necessary to be the same.

user-1 和 user-2 不必相同。

for unix socket, user-1 need to be the same as user-3,as nginx fastcgi_pass must have read/write permission on the unix socket.

对于 unix socket,user-1 需要与 user-3 相同,因为 nginx fastcgi_pass 必须对 unix socket 具有读/写权限。

otherwise nginx will get 502 Bad Gateway, and nginx error.log has the following error message

否则 nginx 会得到502 Bad Gateway,并且 nginx error.log 有如下错误信息

*36 connect() to unix:/var/run/php-fpm/fpm-www.sock failed (13: Permission denied) while connecting to upstream

*36 connect() to unix:/var/run/php-fpm/fpm-www.sock failed (13: Permission denied) 连接上游时

回答by enRaiser

I dont know how the $document_root is calculated but I resolved the issue , by really making sure that my document root is at /usr/share/nginx/ just wher the html folder exist

我不知道 $document_root 是如何计算的,但我解决了这个问题,通过真正确保我的文档根目录位于 /usr/share/nginx/ 就在 html 文件夹存在的地方