php中的Nginx:子目录下的php文件抛出404错误

时间:2017-03-16 10:14:43

标签: php nginx amazon-ec2

我的nginx服务器有starnge问题,子文件夹下的php文件抛出404错误,但html文件工作正常。

文件夹结构

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

1 个答案:

答案 0 :(得分: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;
    }
}