【发布时间】:2014-11-01 01:58:33
【问题描述】:
我一直在努力解决这个问题。我无法正确添加路由,否则 nginx 无法正常使用 phalcon。
phalcon tuts 都是基于 apache 的,这无济于事。
问题:我可以访问http://localhost 并获得 index.php,但是当我尝试访问 localhost/signup 时出现“找不到文件”。
index.php 试试 {
//Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../application/controllers/',
'../application/models/'
))->register();
$di = new Phalcon\DI\FactoryDefault();
//Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../application/views/');
return $view;
});
$di->set('url', function(){
$url = new Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
$di->set('router', function() {
$router = new \Phalcon\Mvc\Router();
$router->setUriSource(Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
$router->add(
'/signup',
array(
"controller" => "signup",
"action" => "index"
)
);
return $router;
});
//Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
} catch(\Phalcon\Exception $e) {
echo "PhalconException: ", $e->getMessage();
}
nginx 配置
server {
listen 80;
server_name Tikarta-berkshelf;
root /var/www/;
index public/index.php;
access_log /var/log/nginx/localhost.access.log;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php$ {
#try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index public/index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
SignupController.php
<?php
class SignupController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
echo "hello";
}
}
【问题讨论】: