问题:
http://example.com/(index.php)/ 可以访问(为配置的默认controller-class)
http://example.com/(index.php)/[controller-class]/[controller-method] 不可以访问(提示404错误!)
原因:默认Nginx
不支持pathinfo
这种格式,当你浏览器里输入http:\xxx.xxx.com\index.php\pages\home
的时候,Nginx会认为你要访问index.php目录下的pages文件夹里的home
,所以会报404 not found错误。
方案:
1.修改php
支持pathinfo
找到php的php.ini
文件(可能在php安装目录的etc目录也可能在lib文件夹下,看自己的配置),搜索:cgi.fix_pathinfo
将注释放开,并置为1:cgi.fix_pathinfo=1
2.
改nginx安装目录里的nginx.conf
文件:
##########################################pathinfo 模式
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){
set $real_script_name $1;
set $path_info $2;
}
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
##########################################nginx支持pathinfo 模式的重点
参考:https://www.cnblogs.com/hubing/p/3984002.html