我们最近重新安装了我们的 生产环境 服务器,我们有一个运行多个模块的Yii项目 . 路由部分在重新安装之前运行良好 . 我们多次检查Nginx配置是否存在问题,但一切看起来都很好,实际上我们从旧服务器复制了工作配置 .
问题是,每个请求(在任何子域上)都会导致CHttpException: Unable to resolve the request "default/site/index". 即使我们调用任何控制器或其他任何东西 .
我打开了一个新的子域(没有指定的规则),仅用于测试,它也重定向到此错误 . (即使我们在没有最后两条规则的情况下尝试过)
我们对Yii有以下路由规则:( print_r的结果)
[http://www.domain.dk/<controller:\w+>/<action:\w+>/<wid:\w+>] => default/<controller>/<action>
[http://www.domain.dk/<controller:\w+>/<action:\w+>] => default/<controller>/<action>
[http://www.domain.dk/] => default/site/index
[http://api.domain.dk/<controller:\w+>/<action:\w+>/<wid:\w+>] => api/<controller>/<action>
[http://api.domain.dk/<controller:\w+>/<action:\w+>] => api/<controller>/<action>
[http://api.domain.dk/] => api/
[http://admin.domain.dk/<controller:\w+>/<action:\w+>/<wid:\w+>] => admin/<controller>/<action>
[http://admin.domain.dk/<controller:\w+>/<action:\w+>] => admin/<controller>/<action>
[http://admin.domain.dk/] => admin/site/index
[https://facebook.domain.dk/<controller:\w+>/<action:\w+>/<wid:\w+>] => facebook/<controller>/<action>
[https://facebook.domain.dk/<controller:\w+>/<action:\w+>] => facebook/<controller>/<action>
[https://facebook.domain.dk/] => facebook/site/index
[http://domain.dk/site/page/view/<view:\w+>/] => default/site/page
[http://<module:\w+>.domain.dk/<controller:\w+>/<action:\w+>/<wid:\w+>] => <module>/<controller>/<action>
[http://<module:\w+>.domain.dk/<controller:\w+>/<action:\w+>] => <module>/<controller>/<action>
所有的Nginx配置都是这样的:
server {
listen 80;
server_name api.domain.dk;
access_log /log/api.domain.dk_access.log;
error_log /log/api.domain.dk_error.log;
root /path.to.project/public_html;
include yii-rules.conf;
}
yii-rules.conf
文件有如下常用规则:(我只复制可能有所不同的内容)
charset utf-8;
index index.php;
location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#let yii catch the calls to unexising PHP files
set $fsn /index.php;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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;
}
我们用尽了可能导致此错误的想法,可能只是一个小问题,我们没有注意到:
此错误不会对我们的日志生成任何内容(当然只有访问日志),而yii访问日志只是写入,我们可以在浏览器中看到:“无法解析...”
How should we change our configs or rule list to avoid this error?
1 回答
GOTCHA!
这是一件小事,需要花费一天多的时间才能找到,因为它没有显示任何错误:
我们有我们的主配置文件,我们使用“自定义”配置文件,特别是服务器或开发机器,它是gitignored . 所以问题是,我们将2个配置与内置的PHP的array_merge合并 .
CMap::mergeArray solved our problem.
我们的其他配置和网络服务器就好了 .