使用Nginx运行PHP时找不到文件

2022-08-30 08:47:43

最近我安装了最新版本的Nginx,看起来我很难用它来运行PHP。

以下是我用于域的配置文件:

server {
listen       80;
server_name  localhost;

location / {
    root   /usr/share/nginx/html;
    index  index.php;
}

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

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;
}

}

这是我在错误日志文件上遇到的错误:

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

答案 1

尝试另一个*fastcgi_param*类似的东西

fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;

答案 2

我遇到了“找不到文件”的问题,因此我将“根”定义向上移动到“服务器”括号中,以为所有位置提供默认值。您始终可以通过为任何位置提供自己的根来覆盖它。

server {
    root /usr/share/nginx/www;
    location / {
            #root /usr/share/nginx/www;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}

或者,我可以在我的两个位置定义根。


推荐