2017-03-16 111 views
1

我在我的nginx服務器中有starnge問題,php文件在子文件夾下拋出404錯誤,但是html文件工作正常。Nginx的php:php文件在子目錄下拋出404錯誤

文件夾結構

html<folder> 
    index.php 

    test<folder> 
     test.php //not working 
     test.html //works fine 

Nginx的配置

server { 
    listen  80 default_server; 
     listen  [::]:80 default_server; 
     server_name localhost; 
     root   /var/www/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 /var/www/html$fastcgi_script_name; 
      include  fastcgi_params; 
     } 


}ml 

當訪問<ip-address>/test/test.html工作正常

當訪問<ip-address>/test/test.php 404錯誤。

當訪問<ip-address>工作正常(指向html/index.php文件)。

我已經在html文件夾中添加了權限,在php.ini文件中也啓用cgi.fix_pathinfo=0

+0

可能更適合https://serverfault.com/。 – jhmckimm

回答

1
server { 
    listen 80; 
    server_name localhost; 
    root /var/www/html; 
    autoindex on; 

    location/{ 
    index index.php index.html; 
    } 

    location ~\.php$ { 
    include fastcgi_params; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    try_files $uri $uri/ /index.php; 
    } 
} 
+0

沒有工作:) – Jabaa

+0

這裏是錯誤從error.log'「/var/www/html/50x.html」失敗(2:沒有這樣的文件或目錄)' – Jabaa

+0

你能告訴我你訪問'php '文件或'html'文件? –