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
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

SHUIPING_YANG

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

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

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

打赏作者

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

抵扣说明:

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

余额充值