Nginx为index.php / some / path等URL返回404

时间:2014-10-15 05:18:27

标签: php nginx

当我查询脚本名称后附加了“路径信息”的URL时,Nginx返回404,例如http://example.com/index.php/hello

这是我的配置:

server {
    listen  80;
    root    @PROJECT_ROOT@/;
    index   index.php index.html;

    location ~ \.php$ {
        fastcgi_pass    unix:@PHP_FPM_SOCK@;
        include fastcgi_params;
        fastcgi_read_timeout 300s;
    }
}

我不明白为什么\.php$与该网址不匹配,我尝试搜索类似的问题,但找不到任何有用的内容。

2 个答案:

答案 0 :(得分:2)

使用

  

位置〜^。+。php {

     

fastcgi_split_path_info ^(。+?。php)(/。*)$;

匹配uri中的.php分割参数

答案 1 :(得分:1)

这对我有用:

location ~ \.php {
    # Split the path appropriately
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;

    # Work around annoying nginx "feature" (https://trac.nginx.org/nginx/ticket/321)
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;

    # Make sure the script exists.
    try_files $fastcgi_script_name =404;

    # Configure everything else.  This part may be different for you.
    fastcgi_pass localhost:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}