| |
昨天在从nginx1.7.2升级2.0的过程中发生了一个问题,不管url是什么,都会直接调用default_controller。经排查,问题发生在system/core/URI.php里面,在65行开始的一段代码里,是为CLI方式运行CI写的一段代码,在这里,程序被判断成CLI模式运行,然后试图获取_parse_cli_args,为空,于是调用default_controller。

我使用的webserver是nginx,在配置文件里用urlrewrite去掉了index.php,CI配置文件中的uri_protocol使用的AUTO。

CI2.0中判断是否为CLI方式运行的方法是判断$_SERVER['argv']是否为空,不为空就是CLI,为空就不是。我查php手册,上面是这样说的:When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. 也就是说$_SERVER['argv']不为空的时候还有一种可能,就是GET方式访问网页,那么该元素中的数据就是query string。也就是说CI2.0默认认为不能使用传统的query string方式,否则会导致误判为CLI。

然后继续分析,在nginx中rewrite的规则是********/index.php?$1,注意,用的是问号而不是斜杠,这是nginx的问题,假如用斜杠的话nginx会试图寻找index.php文件夹下的目标文件,会导致404。也就是说比我我请求的是http:/*****/clock,在ci那变成了http:/*****/index.php?clock,所以在判断时$_SERVER['argv']为clock,于是被判断成CLI,而在_parse_cli_args中,又是从$_SERVER['argv']数组的第二个元素开始取,clock作为第一个元素没有被取到,自然_parse_cli_args取到的是空,导致调用了默认控制器。

综上,有两种修正方法,方法1是暂时注释掉URI.php中判断CLI的那一段,方法2是更改config.php中的uri_protocol为QUERY_STRING。当然还有一种方法是修改nginx的rewrite规则,不使用问号,不过这个我不知道怎么改。
by snooda | 分类: 默认分类 | 评论(2) | 引用(0) | 阅读(3151)
Anoymous
2011/09/09 15:43
呵呵,我个人不建议 uri_protocol 使用 AUTO,因为 CI 的判断有时候确实不太准确。
Anoymous
2011/02/26 17:38
good!
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]