Nginx + fastcgi来运行PHP脚本,但它一直告诉我“文件未find”

这是服务器块中的一部分configuration:

我无法执行任何PHP脚本,我在/ var / html test.php了一个名为test.php的文件,但是当我指向http://localhost/test.php ,我得到一个结果:

File not found.

这不是由nginx生成的,因为它不同于nginx的404页面。

 location / { root /var/html; index index.html index.htm; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_intercept_errors on; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } 

我错过了什么?

您正在定义/位置下的文档根目录,这不适用于\.php$位置。 将root指令移到/位置之外,以便将其应用于两者。

 root /var/html; location / { index index.html index.htm; } location ~ \.php$ { ... }