T
T
TyVik2014-01-12 13:39:12
PHP
TyVik, 2014-01-12 13:39:12

How to make CNC work in Nginx via php-fpm?

Good afternoon. There is a project - https://github.com/vladimir-s/personal-maps. Written in Yii, the author transforms internal links according to the following rule:

'urlManager'=>array(	'urlFormat'=>'path',
      'rules'=>array(
                // REST patterns
                array('places/list', 'pattern'=>'api/places', 'verb'=>'GET'),
...
                // regular patterns
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
      ),
            'showScriptName'=>false,
    ),

Everything works under Apache2, but I still don’t understand how to process such URLs (in the REST section) through nginx.
Tried with this config:
server {
        listen 80;
        root /var/www/tyvik/personal_maps/public_html;
        index index.html index.php;
        server_name personal_maps.tyvik.ru;

        location / {
                try_files $uri $uri/ /index.php?r=$request_uri;
        }

        error_page 404 /404.html;

        location ~ \.php$ {
                fastcgi_pass unix:/var/run/php5-fpm.www.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                access_log off;
        }
}

Everything worked, except for REST, it crashes on the request personal_maps.tyvik.ru/api/places, says 404.
Tell me how to explain to nginx what I want?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-01-12
@TyVik

what about yii? the job of apache or in your case nginx is to redirect ALL requests to index.php. Next, yii will parse the original url. So the problem is with the config or with passing parameters to fpm.
the problem in theory is this line:
try_files $uri $uri/ /index.php?r=$request_uri;
the request must be redirected to /index.php/$request_uri
There are a million examples of setting all this under nginx. even in the documentation
www.yiiframework.com/doc/guide/1.1/en/quickstart.a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question