作者:袁立红第_593 | 来源:互联网 | 2014-05-28 09:40
Debian7.0+Nginx+PHP5-FPM+CodeIgniter,首页正常,点其他链接均是Noinputfilespecified,NginxWiki上以及其他网上的解决方案均无效。问题的核心是http://www/abc/def.php/1/2/3这种URL,要把/1/2/3作为PATH_INFO传给/abc
Debian 7.0 + Nginx + PHP5-FPM + CodeIgniter,首页正常,点其他链接均是No input
file specified,Nginx Wiki上以及其他网上的解决方案均无效。
问题的核心是http://www/abc/def.php/1/2/3这种URL,要把/1/2/3作为PATH_INFO传给/abc/def.php,执行的还是/abc/def.php,其实如果不是/abc/def.php而是/index.php恐怕就没问题了,因为Debian中Nginx的默认配置文件处理php的location是这么写的(网上的资料一般也是这么写的):
location ~ \.php$ {
...
}
然后根的location是:
location / {
try_files $uri $uri/ /index.php #
原本最后一个是/index.html
}
结果就是,/abc/def.php/1/2/3匹配进了location
/,然后找不到文件就给改写成了/index.php,然后/index.php不存在于是就显示No input file
specified.
把匹配php的location改为:
location ~ \.php$|.+\.php/.+$ {
...
}
就OK了。
P.S.
1. php.ini里面的cgi.fix_pathinfo要设成0,否则有安全问题。
2.
nginx使用fastcgi_split_path_info解决PATH_INFO的问题,把URL拆成两部分再设好变量SCRIPT_FILENAME和PATH_INFO的内容
3. 不清楚fastcgi_index
index.php;是干什么用的,按location匹配进来的URL不都是带.php的么。
4. try_files的机制稍微有点怪,Nginx文档里说如果最后一个匹配,会做internal
redirect,其他的是internal URI pointer。try_files $uri $uri/
/index.php时,访问/abc/def.php/1/2时会去找/index.php,访问/abc/的时候能找到/abc/index.php(应该是通过$uri/)。如果只写try_files
$uri $uri/,访问/abc/的话却跳不到/abc/index.php(location外面已有index
index.php),日志里说redirection cycle。如果是try_files $uri $uri/
=404;貌似就正常了。