Nginx没有find子目录,也没有在默认目录下运行index.php

我从Apache更改为Nginx,现在我有一些问题。

  1. 当我尝试访问任何文件夹,例如http://devserver/monitor/web ,我有一个Symfony项目,我得到404错误
  2. 当我尝试访问http://devserver我一直得到这个消息File not found.

这就是我的/etc/nginx/conf.d/default.conf文件的样子:

 server { listen 80; server_name devserver; location / { root /var/www/html; index index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # 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; } } 

那里有什么问题?

你已经把你的root指令放在错误的地方。

root应该在server块中定义,而不是在每个location块中定义。 这是最常见的nginx错误configuration之一 。

要解决此问题,请从每个location块中删除所有root指令,并将正确的root指令放在server块中,而不是位于任何location

在一个location块中拥有root的唯一原因是当你真的想为该location使用不同的文档根目录时,比如提供nginx默认错误信息(就像你在这里做的那样)。