我一直在努力解决这个问题。我无法正确添加路由,否则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 config
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";
}
}
答案 0 :(得分:0)
错误的文档根源是这里的问题。 Nginx配置应该是
server {
listen 80;
server_name Tikarta-berkshelf;
root /var/www/public;
index index.php;
access_log /var/log/nginx/localhost.access.log;
location / {
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;
}
}
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 index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}