[PHP] 安装PHP报错“Primary script unknown”的解决方法

前端之家收集整理的这篇文章主要介绍了[PHP] 安装PHP报错“Primary script unknown”的解决方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

当安装完最新版的Nginx和最新版的PHP以后,使用niginx默认配置文件中的PHP配置会有错误
访问指定目录下的PHP文件时,显示File not found.错误。查看Nginx错误日志显示

90#90: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream,client: 127.0.0.1,server: 127.0.0.1,request: "GET /index.PHP HTTP/1.1",upstream: "fastcgi://127.0.0.1:9000",host: "127.0.0.1"

排查的过程:
1.修改默认PHP配置中的fastcgi_param配置fastcgi_param配置,这个地方默认的是/Scripts$fastcgi_script_name

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

2.把root指令从location /{}块里面拿到外面,因为看fpm的access日志,访问PHP文件报的404错误

最简配置如下:

server {
    listen       80;
    server_name  127.0.0.1;
    access_log  /var/log/Nginx/default.access.log  main;
    error_log /var/log/Nginx/default.error.log;
    root   /var/www/html;
    location / {
        index  index.html index.htm;
    }
    location ~ \.PHP$ {
        fastcgi_pass   0.1:9000;
        fastcgi_index  index.PHP;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

 

猜你在找的PHP相关文章