为什么$#u服务器[';脚本#u名称';]返回';php';当我使用nginx重写时?

为什么$#u服务器[';脚本#u名称';]返回';php';当我使用nginx重写时?,php,nginx,yii,Php,Nginx,Yii,我使用的是YII框架,在Apache服务器上一切正常,但在Nginx上却出现了错误。 当我请求URL www.test.com/index.php/a/b时,$_服务器['SCRIPT\u NAME']返回'/index.php',这正是我所需要的,但是当我请求URL www.test.com/a/b时,它被重写为名为'index.php'的同一个文件,$_服务器['SCRIPT\u NAME']结果是'index.php',这与Apache不同。我的nginx配置如下: server {

我使用的是YII框架,在Apache服务器上一切正常,但在Nginx上却出现了错误。 当我请求URL www.test.com/index.php/a/b时,$_服务器['SCRIPT\u NAME']返回'/index.php',这正是我所需要的,但是当我请求URL www.test.com/a/b时,它被重写为名为'index.php'的同一个文件,$_服务器['SCRIPT\u NAME']结果是'index.php',这与Apache不同。我的nginx配置如下:

server {
    set $host_path "/data/yii/application";
    access_log  off;

    server_name www.yii.com;
    root   $host_path;
    set $yii_bootstrap "index.php";

    charset utf-8;

    location / {
        index  index.html $yii_bootstrap;
        try_files $uri $uri/ $yii_bootstrap?$args;
    }

    location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;
    }

    #avoid processing of calls to unexisting static files by yii
    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

        fastcgi_pass   127.0.0.1:9001;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;

        #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }

    location ~ /\.ht {
        deny  all;
    }
}
这部分是错误的:

set $yii_bootstrap "index.php";

location / {
    index  index.html $yii_bootstrap;
    try_files $uri $uri/ $yii_bootstrap?$args;
}
应该是:

location / {
    index  index.html index.php;
    try_files $uri $uri/ /index.php$uri?$args;
}
另见:

--

这部分:

location ~ \.php {
    fastcgi_split_path_info  ^(.+\.php)(.*)$;

    #let yii catch the calls to unexising PHP files
    set $fsn /$yii_bootstrap;
    if (-f $document_root$fastcgi_script_name){
        set $fsn $fastcgi_script_name;
    }

    fastcgi_pass   127.0.0.1:9001;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;

    #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
    fastcgi_param  PATH_INFO        $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
}
必须替换为:

location ~ ^(?<script>.+\.php)(?<pathinfo>.*)$ {
    try_files $script =404;

    fastcgi_pass   127.0.0.1:9001;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$script;

    #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
    fastcgi_param  PATH_INFO        $pathinfo;
    fastcgi_param  PATH_TRANSLATED  $document_root$script;
}
必须是:

root /data/yii/application;

因为nginx的工作方式不同。也许您应该报告一个bug。@Ignacio Vazquez Abrams它的配置不同。它完全按照配置方式进行操作。
root /data/yii/application;