先说几个大坑:
一、先确认/baas/config/db.config.xml中的数据库连接各参数无误...我今天就因为密码不对(重装mysql,默认密码变了)调试了大半天。
二、确认php-fpm中配置的用户与nginx中配置的用户一致,且nginx站点根目录中对应用户的权属权限正常。
三、请把\model\Baas.php下的weixin这个目录也带上,或者将index.php中对其的引用注释掉,注释掉后是否正常未经测试,如果不是强迫症人士,建议带上weixin目录即可。
四、无论是否启用pathinfo,都需要以下这个rewrite:
-------------------------------------------------------------------
location /baas/ {
index index.html index.htm index.php;
#autoindex off;
rewrite /baas/(.*) /baas/index.php/$1 last;
}
-------------------------------------------------------------------
因为前台xhr的post指向是/baas/包名/模块名/方法名 这种,需要rewrite成为/baas/index.php/包名/模块名/方法名,上面location正则该怎么写,大家可以自由发挥,达到目的即可。
由于密码错误的原因,导致一下午的尝试都是白瞎,关于cgi.fix_pathinfo=0的配置方法暂时无法确认,先讲cgi.fix_pathinfo=1下的配置方法:
1、配置文件中php文件指向及处理:
-------------------------------------------------------------------
location ~ .php {
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
-------------------------------------------------------------------
2、包含的fastcgi_params文件:
-------------------------------------------------------------------
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
-------------------------------------------------------------------
其他的官方教程里都有讲,就不赘述了。http://docs.wex5.com/wex5-runtime-php/
参考资料:http://www.jb51.net/article/28050.htm
学习资料:http://www.nginx.cn/426.html
部署调试过程中,建议打开display_errors,
可将Engine.class.php中
$module_file = $requirePath.$action->Clazz.'.php';
//echo $module_file;
的注释拿掉:echo $module_file;(能够正常拿到xhr返回包后记得要还原注释,否则影响正常访问,造成其绑定的baasdata组件定义失败,web会提示data组件未定义)
或改动/baas/index.php:
$paramObject = $this->GetParams($reg);
echo $_SERVER['PHP_SELF']; //可在/baas/index.php中此处加这一句,方便调试,同样,调完请恢复。
if($_SERVER['PHP_SELF'] == '/baas/index.php')
{
$URL = $_SERVER['REQUEST_URI'];
$ret = Engine::ExecAction('/baas/index.php'.substr($URL,5,strlen($URL)), $paramObject);
}
访问这种连接: /baas/index.php/$packageName/$module_file/$action
例如http://libra.tpddns.cn:8088/baas/workreport/login/queryUser,当然,得选择那种不传参的默认action,
反面举例(自定义传参的action):http://libra.tpddns.cn:8088/baas/index.php/workreport/mission/queryMission
如果看到显示workreport/Login__do.php 加上返回xhr包的内容,那么恭喜你,大工告成了。
补充cgi.fix_pathinfo=0的配置:
---------------------------------------------------------------------------
location ~ .php {
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $1$2;
}
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
---------------------------------------------------------------------------
或使用fastcgi_split_path_info(传说新版推荐):
---------------------------------------------------------------------------
location ~ ^.+\.php {
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name$fastcgi_path_info;
}
---------------------------------------------------------------------------
其余同上。好了,感觉去了一块心病...