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.

phalcon routes not working with nginx in windows.Each time it opens index page

I open any other page it always opens up index page, routes are not properly working for phalcon app. whenever i try to open other page with different route it always open index page. My nginx.conf is below, Please check and suggest for correction.

server {

listen       85;
server_name  localhost;

#charset koi8-r;
root   abc.example.com;
index  index.html index.htm index.php;
#access_log  logs/host.access.log  main;

autoindex on;

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

location ~ \.php {

fastcgi_pass  127.0.0.1:9000;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info       ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO       $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}

# general static 
location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ { 
root abc.example.com; 
} 



# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny  all;
}
}


61.0k

i think you missed something here :

location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args; 
    }
edited Apr '17

Recommended way to setup FrontPageController in relation with nginx and PhalconPHP would be:

try_files $uri $uri/ /index.php$is_args$query_string;

In / location block.

P.S. even w/o query string routes are working fine if you set your router service to read from REQUIST_URI.

$di->setShared('router', function (){
// Phalcon\Mvc\Router has a default behavior that provides a very simple routing that always expects a URI that matches the following pattern: /:controller/:action/:params

        $router = new \Phalcon\Mvc\Router(false); //Create the router without default routes

        //we're using Front Page Controller pattern in relation from nginx -> Phalcon
        $router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI); // Use $_SERVER['REQUEST_URI']

        //Set whether router must remove the extra slashes in the handled routes
        $router->removeExtraSlashes(true);

    return $router;
});

P.S. I still vote strongly against Windows for any production env.

i tried it. it do not work for me.



61.0k

paste us you config again, take a look at https://docs.phalconphp.com/en/3.0.0/reference/tutorial.html again. Because it rather simple exaple and it should work out of the box pretty fast.

Here is my configuration...

server {
    listen       85;
        server_name  localhost;
        #charset koi8-r;
        root   /html;
        index  index.html index.htm index.php;
        #access_log  logs/host.access.log  main;
          location / {
        try_files $uri $uri/ /index.php;
    }

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

    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root  E:/Nginx1103/html;
    }

    # general static 
    location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ { 
        root /html; 
    } 

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}


61.0k
Accepted
answer
server {
    listen       85;
        server_name  localhost;
        #charset koi8-r;
        root   /html;
        index  index.html index.htm index.php;
        #access_log  logs/host.access.log  main;
          location / {
            try_files $uri $uri/ /index.php?_url=$uri&$args; 
         }

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

    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root  E:/Nginx1103/html;
    }

    # general static 
    location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ { 
        root /html; 
    } 

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

can you try with this one ?

Trying this .. result is 404 Not Found .

Please help me out in this , i've tried almost all answers from stackoverflow but result is still an issue.



61.0k

check access log, but probably your phalcon application ( the router ) is not set correctly.

see if you are hitting the correct index.php with die('hi') at line 0 or something



61.0k

you should do the hello world https://docs.phalconphp.com/en/3.0.0/reference/tutorial.html . There everything is simple and config is 5 lines. You got 50 here, no idea idea what's breaking it. Might be something unrelated

if you can join phalconchats.slack.com and find me there @izo to speed/easy it up a bit

i'have tried index.php and router file , controll is working proper there by echoing text there , it works.

its all working nice on wamp apachi.



61.0k
 try_files     $uri =404;

this look susspicious in the config.

its your nignx config that is screwed then.

server {
    listen      85;
    server_name localhost;
    root        /html;
    index       index.php index.html index.htm;
    charset     utf-8;

    location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    location ~ \.php {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index /index.php;

        include fastcgi_params;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

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

how about with this config

add me in your team.

now the error is (project_name)Controller handler class cannot be loaded

i can send you sample of app , please configure it for me.



61.0k

it means where you decreate Loader something is wrong

hey Izo , i'm here with different account , can i send you sample of app?



61.0k

join slack https://phalconchats.slack.com and find me there, @izo

edited Apr '17

How can i join this, i do not have an email on phalcontip.

If you have an @phalcontip.com email address, you can create an account.

edited Apr '17

i've uploade a sample project. Same issue is with this. Check this one please. https://github.com/tariqali021/phalcon-nginx