FastCGI sent in stderr: "Primary script unknown" while reading response head

109 篇文章 7 订阅

nginx和php-fpm不能通信,网上各种办法都试过,就是不行,后来换了一下root的位置就解决了!
出现这个原因有三:

1、文件不存在

2、php-fpm 与nginx不能通信

3、root位置错误

文件位置:/etc/nginx/conf.d

server {
    listen       80;
    server_name  localhost;

    access_log  /var/log/nginx/log/host.access.log  main;
    root   /usr/share/nginx/html;  #原本这个设置是在下面localtion里面的

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

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;  #网上很多人说这个地方有的没配置,但是我是按照php官方的来配置的,就有这个
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }


}

nginx主配置文件:


user  www-data www-data;     #用户组,要和php-fpm里面一致
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;   #注意看这里,引用虚拟机配置文件
}

就这样就成了。

虚拟主机也可以下面这样配置:

server{
        listen 80;
        server_name  localhost;
        root         /usr/share/nginx/html;
        index index.php;
        location ~ .*.php?$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
            index index.php index.html;
          }
        if (!-e $request_filename) {
         rewrite ^/(.*)$ /index.php?s=$1 last;
        }
}

效果一样,但是这种可以配合框架使用。自动分理出模块控制器和方法。

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
FastCGI sent in stderr: "primary script unknown" 是一种错误信息,它通常发生在使用PHP时。它的意思是FastCGI无法找到要执行的主要脚本。在Web服务器和PHP之间的通信中,FastCGI是一个桥梁。当您请求一个PHP脚本时,Web服务器将请求发送到FastCGI进程,然后再由FastCGI进程执行该脚本并将结果返回给Web服务器。 当出现"primary script unknown"错误时,它通常是由以下原因之一引起的: 1.文件或目录权限不正确 当FastCGI无法访问脚本或目录时,它将返回"primary script unknown"错误。这可能是因为文件或目录权限不正确导致的。确保您的PHP文件和目录具有足够的权限,以便FastCGI可以访问它们。 2.PHP文件缺失或无法使用 如果您的PHP文件丢失或损坏,FastCGI也将无法找到它并返回"primary script unknown"错误。请确保您的PHP文件存在于正确的位置,并且它们是有效的。 3.错误的FastCGI参数 如果您的FastCGI参数不正确,例如指向错误的脚本路径或FastCGI端口,也会导致FastCGI返回"primary script unknown"错误。确保您使用正确的FastCGI参数。 解决这个问题,您可以首先检查文件和目录权限是否正确,确保PHP文件存在,并且检查您的FastCGI参数是否正确。如果问题仍然存在,请尝试重新安装FastCGI和PHP,并确保它们都是最新的版本。同时,查看PHP和FastCGI的错误日志以获取更多详细信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值