Phalcon and nginx - framework run only indexController

不打扰是莪最后的温柔 提交于 2019-12-20 03:56:01

问题


I am using Phalcon and Nginx, and i have a problem. When I go to http://myapp.dev/segmentation Phalcon should run SegmentationController and its indexAction() method. But instead, Phalcon is running IndexController(default controller for "/"). I think problem is with Nginx configuration, because all works fine under Apache.

Here is my Nginx site configuration:

server {

    listen   80;
    server_name myapp.dev;

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

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

    location ~ \.php$ {

        try_files $uri $uri/ =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

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

    location ~ /\.ht {
        deny all;
    }

    location /phpmyadmin {

       root /usr/share/;
       index index.php index.html index.htm;

       location ~ ^/phpmyadmin/(.+\.php)$ {

            try_files $uri $uri/ =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;

            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
       }

       location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
         root /usr/share/;
       }

     }
}

回答1:


USe this config

try_files $uri $uri/ @rewrite;

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

Working Config




回答2:


Its the problem with location directive

Use this configuration.

location / {
        root   $root_path;
        index  index.php index.html index.htm;

        # if file exists return it right away
        if (-f $request_filename) {
            break;
        }

        # otherwise rewrite it
        if (!-e $request_filename) {
            rewrite ^(.+)$ /index.php?_url=/$1 last;
            break;
        }

Hope this helps!

Happy Coding !!!



来源:https://stackoverflow.com/questions/25096422/phalcon-and-nginx-framework-run-only-indexcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!