NGINX 不执行 PHP 文件

Gab*_*lla 10 php nginx

我找不到答案。安装了 PHP5 + NGINX + PHP-FPM 并且无法执行 php 文件,它得到一个“哎呀!这个链接似乎被破坏了”。铬错误。我没有任何有价值的错误日志报告,我的根目录中有一个 index.php,尝试创建一个自定义的 phpinfo.php 文件,但都没有奏效。

我可以加载 HTML 文件,但不能加载 PHP。

这是我在 NGINX 中的本地站点配置:

server {
    listen       80;
    server_name  im;
    access_log /var/www/website/access.log;
    error_log /var/www/website/error.log;

    location / {
        root   /var/www/website;
        index  index.html index.htm index.php;
    }


    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/website$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

}
Run Code Online (Sandbox Code Playgroud)

将所有目录的所有权更改为 www-data:www-data,在 php 文件上做了一个 777,什么都没有。重启nginx,FPM,什么都没有。

帮助?:(

qua*_*nta 9

它得到一个“糟糕!此链接似乎已损坏。” 铬错误。

如果错误页面少于 512 字节,Chrome 会显示自己的错误页面。

我怀疑您在以下行中fastcgi_params

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
Run Code Online (Sandbox Code Playgroud)

如果是这样,因为在root中定义的指令location /将永远不会应用于location ~ \.php$,因此SCRIPT_FILENAME成为 URI。

这可以通过将root指令移动到server级别上下文来解决:

server {
    listen       80;
    server_name  im;
    access_log /var/www/website/access.log;
    error_log /var/www/website/error.log;

    root   /var/www/website;

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

}
Run Code Online (Sandbox Code Playgroud)