Question

We recently reinstalled our production server, where we have a Yii project running with multiple modules. The routing part was working well before the re-installation. We checked the Nginx configs several times for problems, but everything looks good, and actually we copied the working configs from the older server.

The problem is, every request (on any subdomain) results an CHttpException: Unable to resolve the request "default/site/index". Even if we call any controller or anything else.

I opened a new subdomain (what have no specified rules), just for test and it also redirected to this error. (even we tried it without the two last rules)

We have the following routing rules for Yii: (result of 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>

All the Nginx configs looks like this:

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;
}

The yii-rules.conf file have common rules like: (I only copy what can make a difference)

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;
}

We ran out of ideas what can cause this error, probably just a small issue what we do not notice :\

This error doesn't generate anything to our logs (only the access logs of course) and the yii access log is only writing, what we can see in the browser: "unable to resolve..."

How should we change our configs or rule list to avoid this error?

Was it helpful?

Solution

GOTCHA!

It was a small thing, that took more then a day to find, because it did not showed any errors:

We have our main config file and we use a "custom" config file, specifically to the server or the development machines and it is gitignored. So the problem was, that we merged the 2 configs with the built in PHP's array_merge.

CMap::mergeArray solved our problem.

Our other configs and webserver was just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top