NGINX + Codeigniter不工作不能访问控制器并将参数发送给控制器

我想在NGINX下运行codeigniter,但它不工作。 我想能够发送一个参数到控制器的方法。 但到目前为止,我甚至无法使用地址example.com/index.php/welcome.php访问控制器。 它说没有指定input文件 。 但是,当我键入example.com/index.php/它redirect到欢迎控制器。 我会说我已经尝试了互联网上的所有nginxconfiguration文件。

这是我的ngnixconfiguration

server { ## Your website name goes here. server_name compute.amazonaws.com; ## Your only path reference. root /var/www/; listen 80; ## This should be in your http block and if it is, it's not needed here. index index.html index.htm index.php; location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { expires max; log_not_found off; } # location / { # This is cool because no php is touched for static content #try_files $uri $uri/ /index.php?q=$uri&$args; # try_files $uri $uri/ /index.php; # location / { try_files $uri $uri/ /index.php?$args; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } } location ~ \.php$ { #try_files $uri =404; #fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_split_path_info ^(.+\.php)(.*)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } 

这是我的欢迎控制器

  <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { function __construct() { parent::__construct(); } function index() { $this->load->helper('url'); $this->load->view('welcome_message'); } function a($a) { echo "AHOJ "; echo $a; } } 

我希望能够从欢迎控制器调用函数a并获得响应。 基本我想build立一个REST服务器,这是我的routes.php

  $route['default_controller'] = "welcome"; $route['404_override'] = ''; $route['test_welcome'] = 'welcome'; $route['api/v1/(:any)'] = "api_v1/$1"; $route['item/(:any)'] = "item/show_item/$1"; $route['scaffolding_trigger'] = ""; 

重要的路线是$ route ['api / v1 /(:any)'] =“api_v1 / $ 1”; 我想要这个工作。

这是我的codeigniter config.php

  $config['base_url'] = ''; $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI'; 

请以某种方式帮助我。 非常感谢你

最后我得到了它的工作。 我使用了https://gist.github.com/lynxluna/1050850&#x7684; nginxconfiguration并修改了一下。 这是我的configuration

  server { # GENERAL CONFIGS listen 80; server_name example.com .example.com; root /var/www; index index.html index.htm index.php; location ~* \.(ico|css|js|gif|jpe?g|png)$ { expires max; add_header Pragma public; try_files $uri /index.html; } # ROOT Location location / { try_files $uri $uri/ @rewrites; } location @rewrites { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } } location = /favicon.ico { access_log off; log_not_found off; } location ~ /\. { access_log off; log_not_found off; deny all; } # PHP Configs fastcgi_intercept_errors on; location ~ \.php { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_index index.php; fastcgi_pass unix:/var/run/php5-fpm.sock; } }