Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

No other controllers reachable (Phalcon/Nginx).

Hi all,

I got a, probably very simple, problem with Phalcon/Nginx. I got the first demo up and running perfectly in a Vagrant/Puppet VM setup, however when I add a new controller (Say SearchContoller(.php)) I can't reach that controller with the /search url. It always shows the result of the IndexController.

So I guess something is wrong with my routing (no specific routing object setup yet) or with my Nginx configuration. I'm used to using .htaccess files in Apache...

This is my Nginx configuration for the vhost:

server {

    listen   80;
    server_name localhost.dev;

    index index.php index.html index.htm;
    set $root_path '/var/www/phalcon/public';
    root $root_path;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}

If more information is required I'll gladly provide it.

Thank you for your help!



3.4k
Accepted
answer
edited Aug '14

Replace

location / {
    try_files $uri $uri/ /index.php;
}

with

try_files $uri $uri/ @rewrite;

location @rewrite {
    rewrite ^/(.*)$ /index.php?_url=/$1;
}

Full config i use to get basic stuff running

server {
    server_name *.sitename.fr sitename.fr;
    listen 80;
    port_in_redirect off;
    server_tokens off;
    autoindex off;
    charset      utf-8;

    set $root_path /var/www/sitefolder/public/;
    root $root_path;

    index index.php index.html index.htm;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_pass php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;


    }

}

That did the trick. Thank you for your time!