【问题标题】:Phalcon and nginx - framework run only indexControllerPhalcon 和 nginx - 框架只运行 indexController
【发布时间】:2014-08-03 00:29:12
【问题描述】:

我正在使用 Phalcon 和 Nginx,但我遇到了问题。 当我去http://myapp.dev/segmentationPhalcon 应该运行 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/;
       }

     }
}

【问题讨论】:

    标签: php nginx webserver phalcon


    【解决方案1】:

    使用这个配置

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

    工作配置

    【讨论】:

      【解决方案2】:

      位置指令的问题

      使用此配置。

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

      希望这会有所帮助!

      编码愉快!!!

      【讨论】:

      • 感谢您的回答,但此配置不起作用。我重新启动了 nginx 和 fpm,但它仍然没有改变任何东西。
      • 试试这个 try_files $uri $uri/ @rewrite;位置 @rewrite { 重写 ^/(.*)$ /index.php?_url=/$1; }
      • 是的,就是这样!感谢帮助!也许你应该用正确的配置写下一个答案,我可以把它标记为正确的答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      相关资源
      最近更新 更多