2

I want to run codeigniter under NGINX but it just doesnt work. I want to be able to send a parameters to controllers methods. But so far I can not even access controller using the address example.com/index.php/welcome.php. It says No input file specified. However when I type example.com/index.php/ it redirects to welcome controller. I would say I have tried all nginx config files on the internet.

this is my ngnix config

  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;
          }
  }     

this is my welcome controller

           <?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;
            }
           }

I want to be able to call function a from welcome controller and get response. Basicaly I want to build a REST server and this is my 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'] = "";

The important line is $route['api/v1/(:any)'] = "api_v1/$1"; I want this to work.

This is my codeigniter config.php

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

Please help me somehow. Thank you very much

4

Finally I got it working. I have used nginx config from https://gist.github.com/lynxluna/1050850 and modified it a little bit. This is my config

     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;
         }
     }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.