2014-08-31 53 views
2

我有了这个非常简单的服务器块下网站可用Nginx的网站,提供不工作

问题:当我尝试进入mydomain.com,Nginx的返回«404未找到»,但如果我尝试进入特别文件,它工作正常,如mydomain.com的index.php

server { 

    listen   80; 
    index   index.php; 
    server_name  mydomain.com; 
    root   /home/myusername/sites/mydomain.com/htdocs; 

    access_log  /home/myusername/sites/mydomain.com/logs/access.log; 
    error_log  /home/myusername/sites/mydomain.com/logs/error.log; 

    location/{ 
      try_files $uri =404; 
    } 

    location ~ \.php$ { 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      include fastcgi_params; 
    } 

} 

需要注意的是:

  • 主机文件配置;
  • 每次编辑后我重新启动Nginx;
  • 访问权限,用户和组是否正确;
  • error.log文件为空,access.log返回所有404;
  • 我试图通过添加/删除一些行来改变配置,仍然没有改变;
  • 该网站启用网站启用与正确的符号链接(我试图编辑它,它打开了正确的文件);
  • 我有谁运行良好,在同一台服务器上的几个网站(所以包括网站可用网站启用是确定的,而Nginx的正常工作)。

回答

1

所以,答案是送礼者给我的ServerFault通过Alexey Ten,这里就是答案


try_files指令是过于严格的副本,并且,我猜,是在错误的地点。

要么完全删除location /,这没有多大意义,或者,至少要加上$uri/这样index指令才能工作。

try_files $uri $uri/ =404; 

但我的猜测是,你需要移动这个try_fileslocation ~ \.php$,这将确保PHP文件exsists之前将它传递给PHP-FPM处理。所有其他文件将由nginx在适当使用index指令的情况下提供。

server { 
    listen   80; 
    index   index.php; 
    server_name  mydomain.com; 
    root   /home/myusername/sites/mydomain.com/htdocs; 

    access_log  /home/myusername/sites/mydomain.com/logs/access.log; 
    error_log  /home/myusername/sites/mydomain.com/logs/error.log; 

    location ~ \.php$ { 
      try_files $uri =404; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      include fastcgi_params; 
    } 
}