无法在全新安装中设置nginx + php5-fpm获取404

我只是下载了nginx 1.4,马上就看到“Welcome to nginx!” 消息,那么我已经安装了php5-fpm ,所以我在/usr/share/nginx/html/demo.php上创build了一个php文件,只是用<?php echo "Hello World"; ?> <?php echo "Hello World"; ?>里面。

(我试着在ElementaryOS Ubuntu 12.04的基础上),并遵循本手册: http : //wiki.nginx.org/PHPFcgiExample

然后当我访问http://localhost/demo.php它不起作用,我给了一个404错误。 这是我的/etc/nginx/conf.d/default.conf文件:

 server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } 

我认为这是一个权限问题,所以我只是将用户nginx更改为用户WWW数据,这是与fpm使用(根据conf文件)相同的用户。 然后我申请chown -R www-data:www-data /usr/share/nginx/html/但是我有同样的错误。

我正在寻找类似的问题,我读到:

 root /usr/share/nginx/html; index index.html index.htm; 

他们需要在服务器级别(不是本地/),如果我这样做,我得到一个空白页面,但没有别的。 分析标题,我得到一个200 Ok的回应。

如果我使用默认的php snnipet而不是手册中的那个:

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

我给了一个404错误,但只在一个空白页面和消息“文件未find”。 这个呈现的页面与我之前获得的不同。 我觉得这个来自fpm,另一个来自nginx(当然..我不知道)。

最后我做了chmod 777 /usr/share/nginx/html/demo.php ,现在下载脚本,下载文件demo.php到我的电脑。

所以我想知道,我怎样才能用nginx + php5-fpm执行PHP脚本。 我不介意删除和清除nginx,fpm或php包,我只是想在web服务器上执行一个php脚本。

提前致谢。 祝你有美好的一天。

configuration行:

  fastcgi_pass 127.0.0.1:9000; 

正在指导nginx将请求转发到监听localhost端口9000的进程。你有听什么东西吗?