尝试运行Zend应用程序时,在应用程序文档根请求上得到404。
这个404是由Zend框架的/Application/view/errors/404.php
页面呈现的,而不是服务器的404页面。
我在Linux上安装了Nginx和php-fpm以及MariaDB来运行这个Zend应用程序。
我将php执行附加到php Eclipse XDebug调试器,该调试器显示正在运行的index.php页面,直至其Zend'Mvc'Application::init
调用。
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend'Mvc'Application::init(require 'config/application.config.php')->run();
我已经配置Nginx虚拟主机:
$ cat programs/install/nginx/conf/sites-available/nginx-dev.extrapack.my-group.com
server {
listen 80;
server_name dev.extrapack.my-group.com;
root /home/stephane/dev/php/projects/my/Extrapack-Mon/public;
index index.php;
include /home/stephane/programs/install/nginx/conf/security;
access_log /home/stephane/programs/install/nginx/logs/access.log;
error_log /home/stephane/programs/install/nginx/logs/error.log notice;
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
access_log off;
log_not_found off;
expires max;
}
location ~ '.php$ {
try_files $uri = 404;
fastcgi_index index.php;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS 'on'; # Make PHP-FPM aware that this vhost is HTTPs enabled
fastcgi_param APPLICATION_ENV development;
include fastcgi_params;
fastcgi_split_path_info ^(.+'.php)(.*)$;
}
client_max_body_size 20m;
client_body_buffer_size 128k;
}
/Application/config/module.config.php
文件包含:
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application'Controller',
'controller' => 'Index',
'action' => 'index',
),
),
但是IndexController
根本没有被击中,调试器没有在控制器中的任何断点处停止。
我在onBootstrap
回调中添加了这个代码块:
$em->attach('dispatch.error', function($e){
switch ($e->getError()) {
case 'error-router-no-match':
break;
}
}, -100);
和调试器停止在break;
行的断点,这意味着错误是一个error-router-no-match
。
这是当我运行调试配置时调试器请求的url:http://dev.extrapack.group.com/index.php?XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=14776859837352
作为一个Zend新手,我不知道我还能提供什么帮助,但如果我的问题中缺少一些配置,我很乐意添加。
我使用的是Zend version 2.4.9.
编辑:我添加了一个SSL虚拟主机,使应用程序最终能够显示其用户登录页面,解决了这个问题。
server {
listen 443;
server_name dev.extrapack.group.com;
root /home/stephane/dev/php/projects/Extrapack-Mon/public;
ssl on;
ssl_certificate /home/stephane/programs/install/nginx/conf/sites-available/extrapack.group.com.crt;
ssl_certificate_key /home/stephane/programs/install/nginx/conf/sites-available/extrapack.group.com.key;
location /simplesaml {
index index.php;
alias /usr/share/simplesaml/www;
location ~ ^/simplesaml/(module'.php)(/.+)$ {
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_split_path_info ^/simplesaml/(module'.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /usr/share/simplesaml/www/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
}
location ~ '.php$ {
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
}
}
location / {
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_split_path_info ^(.+'.php)(.*)$;
try_files $uri /index.php?$args;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS 'on'; # Make PHP-FPM aware that this vhost is HTTPs enabled
fastcgi_param APPLICATION_ENV development;
fastcgi_index index.php;
}
}
您的url应该映射为http://dev.extrapack.group.com作为http服务器上的默认路径,而不是http://dev.extrapack.group.com/index.php。