又一个 FastCGI Primary Script Unknown 错误(nginx、php5-fpm)

Posted

技术标签:

【中文标题】又一个 FastCGI Primary Script Unknown 错误(nginx、php5-fpm)【英文标题】:Yet another FastCGI Primary Script Unknown error (nginx, php5-fpm) 【发布时间】:2014-11-27 15:01:01 【问题描述】:

这是我来自 nginx 的 error.log:

2014/10/02 14:51:29 [error] 15936#0: *1 FastCGI sent in stderr: "Primary script unknown" 同时从上游读取响应标头,客户端:134.106.87.55,服务器:sumomo.shitteru2 .net,请求:“GET /index.php HTTP/1.1”,上游:“fastcgi://unix:/var/run/php5-fpm.sock:”,主机:“sumomo.shitteru2.net”

这是我启用的网站:

server 
     listen 80;
     server_name sumomo.shitteru2.net;

     index index.php index.html index.htm;

     location / 
             root /mnt/firstsite;
     

     location ~ [^/]\.php(/|$) 
             fastcgi_split_path_info ^(.+?\.php)(/.*)$;
             if (!-f $document_root$fastcgi_script_name) 
                     return 404;
             
             fastcgi_pass unix:/var/run/php5-fpm.sock;
             fastcgi_index index.php;
             include fastcgi_params;
     

据我所知,一切都非常简单,所以它应该可以工作。我什至直接从http://wiki.nginx.org/PHPFcgiExample#Connecting_nginx_to_PHP_FPM 复制了它。你们有没有发现任何潜在的问题?

【问题讨论】:

看看这个serverfault.com/questions/517190/… 【参考方案1】:

我在 /etc/nginx/sn-ps/common.conf 中创建了一个可以在任何地方使用的解决方案:

index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$
                                                                                
    include snippets/fastcgi-php.conf;                                                                                      
    # With php5-fpm:                                                                                                        
    fastcgi_pass unix:/var/run/php5-fpm.sock;    

现在我所有的站点配置文件看起来都非常简单:

server 
    listen 80;
    listen [::]:80;

    server_name do-it-big.com www.do-it-big.com;
    root /var/www/doitbig;
    client_max_body_size 10m;
    include snippets/common.conf;
    location / 
        try_files $uri $uri/ /index.php?$args;
    

【讨论】:

以上是关于又一个 FastCGI Primary Script Unknown 错误(nginx、php5-fpm)的主要内容,如果未能解决你的问题,请参考以下文章

nginx FastCGI错误Primary script unknown解决办法

nginx FastCGI错误Primary script unknown解决办法

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

如何调试“FastCGI sent in stderr: Primary script unknown while reading response header from upstream”并找到实

FastCGI sent in stderr: "Unable to open primary script:index.php (Operation not permitted) 问题解

Nginx报Primary script unknown的错误解决