We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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!



5.0k
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!