Phalcon和nginx - 框架只运行indexController

时间:2014-08-02 15:09:39

标签: php nginx webserver phalcon

我正在使用Phalcon和Nginx,我遇到了问题。 当我去http://myapp.dev/segmentation时,Phalcon应该运行SegmentationController及其indexAction()方法。但相反,Phalcon正在运行IndexController(" /"的默认控制器)。我认为问题在于Nginx配置,因为在Apache下一切正常。

这是我的Nginx网站配置:

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/;
       }

     }
}

2 个答案:

答案 0 :(得分:3)

使用此配置

try_files $uri $uri/ @rewrite;

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

工作配置

答案 1 :(得分:0)

它是位置指令的问题

使用此配置。

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;
        }

希望这有帮助!

快乐编码!!!