【发布时间】:2016-08-08 14:24:55
【问题描述】:
我在 Amazon 上的 EC2 实例上部署的 codeigniter 应用程序存在问题。
$config['base_url'] = 'http://XX.XX.XXX.107/';
$config['index_page'] = 'index.php';
这是我的 route.php(没有任何特定规则)
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
实际上,如果我调用http://xx.xx.xxx.107/,它会正确显示我的第一页(它会加载我的默认控制器 Home.php 并显示 home.php 视图)。 但是,如果我调用例如 http://52.59.107.107/index.php/Home/sign_in_form,而不是显示 sign_in 表单视图,它会再次显示主页视图。
我启用了日志,这就是我得到的
INFO - 2016-08-08 15:43:25 --> Config Class Initialized
INFO - 2016-08-08 15:43:25 --> Hooks Class Initialized
DEBUG - 2016-08-08 15:43:25 --> UTF-8 Support Enabled
INFO - 2016-08-08 15:43:25 --> Utf8 Class Initialized
INFO - 2016-08-08 15:43:25 --> URI Class Initialized
DEBUG - 2016-08-08 15:43:25 --> No URI present. Default controller set.
INFO - 2016-08-08 15:43:25 --> Router Class Initialized
INFO - 2016-08-08 15:43:25 --> Output Class Initialized
INFO - 2016-08-08 15:43:25 --> Security Class Initialized
DEBUG - 2016-08-08 15:43:25 --> Global POST, GET and COOKIE data sanitized
INFO - 2016-08-08 15:43:25 --> Input Class Initialized
INFO - 2016-08-08 15:43:25 --> Language Class Initialized
INFO - 2016-08-08 15:43:25 --> Loader Class Initialized
INFO - 2016-08-08 15:43:25 --> Helper loaded: file_helper
INFO - 2016-08-08 15:43:25 --> Helper loaded: form_helper
INFO - 2016-08-08 15:43:25 --> Helper loaded: url_helper
INFO - 2016-08-08 15:43:25 --> Database Driver Class Initialized
INFO - 2016-08-08 15:43:25 --> Database Driver Class Initialized
INFO - 2016-08-08 15:43:25 --> Session: Class initialized using 'files' driver.
INFO - 2016-08-08 15:43:25 --> XML-RPC Class Initialized
INFO - 2016-08-08 15:43:25 --> Controller Class Initialized
INFO - 2016-08-08 15:43:25 --> Model Class Initialized
INFO - 2016-08-08 15:43:25 --> Model Class Initialized
INFO - 2016-08-08 15:43:25 --> Model Class Initialized
INFO - 2016-08-08 15:43:25 --> Model Class Initialized
INFO - 2016-08-08 15:43:25 --> Form Validation Class Initialized
DEBUG - 2016-08-08 15:43:25 --> Session class already loaded. Second attempt ignored.
INFO - 2016-08-08 15:43:25 --> File loaded: /var/www/core_ci/application/views/header.php
INFO - 2016-08-08 15:43:25 --> File loaded: /var/www/core_ci/application/views/home.php
INFO - 2016-08-08 15:43:25 --> File loaded: /var/www/core_ci/application/views/footer.php
INFO - 2016-08-08 15:43:25 --> Final output sent to browser
DEBUG - 2016-08-08 15:43:25 --> Total execution time: 0.1061
正如您在日志中看到的,我收到 DEBUG - 2016-08-08 15:43:25 --> 不存在 URI。默认控制器设置。,即使我调用这个 url http://xx.xx.xxx.107/index.php/Home/sign_in_form
这里有一些关于我的服务器的数据:
PHP Version 5.5.35
System Linux ip-xx-x-x-xxx 4.4.8-20.46.amzn1.x86_64 #1 SMP Wed Apr 27 19:28:52 UTC 2016 x86_64
Build Date May 2 2016 23:29:10
Server API FPM/FastCGI
这里是 vhost Apache 文件:
<VirtualHost *:80>
# Leave this alone. This setting tells Apache that
# this vhost should be used as the default if nothing
# more appropriate is available.
ServerName default:80
# REQUIRED. Set this to the directory you want to use for
# your “default” site files.
DocumentRoot /var/www/html
# Optional. Uncomment this and set it to your admin email
# address, if you have one. If there is a server error,
# this is the address that Apache will show to users.
#ServerAdmin you@example.com
# Optional. Uncomment this if you want to specify
# a different error log file than the default. You will
# need to create the error file first.
#ErrorLog /var/www/vhosts/logs/error_log
<Directory /var/www/html>
AllowOverride All
</Directory>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
DirectoryIndex /index.php index.php
</VirtualHost>
有没有人可以告诉我哪里失败了?
提前致谢。
更新
主页.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Home_model');
$this->load->model('Users_model');
$this->load->model('Credit_model');
$this->load->library('form_validation');
$this->load->library('language');
$this->load->library('alerts');
$this->load->library('session');
$this->load->helper('url');
// $this->load->helper('captcha');
}
public function test()
{
print_r('my test method');
}
如您所见,为了简单起见,我在 Home 控制器中准备了一个测试方法。 如果我打电话给http://xx.xx.xxx.107/index.php/Home/test,我会得到相同的日志序列,它会显示主视图而不是打印我的原始数据。
似乎由于无法获取正确的 URi,它运行默认控制器。
【问题讨论】:
-
你能显示你的 HomeController.php 代码吗?
-
@MaxGilbert 在更新中查看 Home 控制器的一部分
-
感谢您的更新。该应用程序肯定存在于 www/public_html 文件夹中,没有子目录吗?
-
是的,它位于 /var/www/html 目录中;然后我将 /application 和 /system 目录移出 documentroot 并显然编辑了 index.php 以相应地设置应用程序和系统路径
标签: php codeigniter-3