2016-08-08 100 views
1

我在Amazon上的EC2實例上部署了我的codeigniter應用程序時遇到問題。Codeigniter URI問題...不存在URI。默認控制器集

$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並顯示家庭。 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年8月8日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 

這裏的虛擬主機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 [email protected] 

    # 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> 

是否有任何人可以告訴我我在哪裏失敗?

在此先感謝。

修訂

Home.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,它運行默認控制器。大量的研究後

+0

你能顯示你的HomeController.php代碼? –

+0

@MaxGilbert在更新中看到主控制器的一部分 – agodoo

+0

感謝您的更新。該應用程序絕對存在於www/public_html文件夾中,沒有子目錄進行? –

回答

0

,尋找httpd服務日誌裏面我找到了解決辦法

在虛擬主機文件I取代這行代碼

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1 

與這些的

<FilesMatch \.php$> 
     # 2.4.10+ can proxy to unix socket 
     # SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/" 

     # Else we can just use a tcp socket: 
     SetHandler "proxy:fcgi://127.0.0.1:9000" 
</FilesMatch>