ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

setting up codeigniter on nginx,,

April 06, 2011 10:49pm

Subscribe [3]
  • #1 / Apr 06, 2011 10:49pm

    gunfire20

    2 posts

    hello guys…let me introduce my self as nubie in ci…
    uhm i have little problem here actually…
    i develope ci on apache on my desktop then i want it to online on nginx..
    then the problems begin,,,
    i cant load the default controller, and it just appear error 404
    any one could help me,, i try few tutorials and its not working,,
    i’ll really appreciate if you guys could help me,,,
    thx….
    😊

  • #2 / Apr 07, 2011 12:39am

    Sire

    109 posts

    Please post your nginx configuration for the CI site.

  • #3 / Apr 07, 2011 12:46am

    gunfire20

    2 posts

    Please post your nginx configuration for the CI site.

    thx for response:
    in config.php:
    $config[‘base_url’]  = “http://www.jaxjakarta.com/”;
    $config[‘index_page’] = “index.php”;
    $config[‘uri_protocol’]  = “PATH_INFO”;
    i must use get in this site,,so i cant choose REQUEST_URI
    here is the nginx configuration:
    location /  {
    root /home/jaxjkt/public_html;
    index index.html index.php;
    if (-f $request_filename) {
    expires max;
    break;
    }
          if (!-e $request_filename) {
    rewrite . /index.php last;
    }
          }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|swf|wav)$ {
    expires max;
    }

    location ~ \.php {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param SCRIPT_FILENAME /home/jaxjkt/public_html/index.php;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    }
          location ~ /\.ht {
    deny all;
    }
      }

    any ideas?

  • #4 / Apr 25, 2011 6:12am

    Bangon Kali

    13 posts

    Hi, I just recently tried to setup my CI project on Nginx. I’m using Nginx 1.0.0 (Stable) on Amazon Micro Linux AMI.

    This is the best I could come for the configuration:

    user  nginx;
    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        sendfile        on;
        #tcp_nopush     on;
        
        upload_progress uploads 100M; 
        
        keepalive_timeout  65;
    
        gzip  on;
    
        server {
            listen       80;
            server_name  ec2-175-41-199-2.ap-northeast-1.compute.amazonaws.com;
    
        client_max_body_size 10m;
        
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   /usr/local/nginx/html;
                index  index.php index.html index.htm;
            }
    
        # enforce NO www
        if ($host ~* ^www\.(.*))
        {
            set $host_without_www $1;
            rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        }
     
        # canonicalize codeigniter url end points
        # if your default controller is something other than "welcome" you 
        # should change the following
        if ($request_uri ~* ^(/album(/index)?|/index(.php)?)/?$)
        {
            rewrite ^(.*)$ / permanent;
        }
     
        # removes trailing "index" from all controllers
        if ($request_uri ~* index/?$)
        {
            rewrite ^/(.*)/index/?$ /$1 permanent;
        }
     
        # removes trailing slashes (prevents SEO duplicate content issues)
        if (!-d $request_filename)
        {
            rewrite ^/(.+)/$ /$1 permanent;
        }
     
        # removes access to "system" folder, also allows a "System.php" 
        # controller
        if ($request_uri ~* ^/system)
        {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
        }
     
        # unless the request is for a valid file (image, js, css, etc.), send 
        # to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
        }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                deny  all;
            }
        }
    }

    Because my solution is so messed up, I had to zero-length the base_url in order for it to work. Because if I put something in there, it gets prefixed to the main URL. For example if the URL the user is using to get to my site is mysite.com/welcome/index the final URL becomes mysite.com/mysite.com/welcome/index. It’s very bad, the only solution I found to fix it is this.

    $config['base_url']     = '';

    Additionally, when using my configuration (which btw is a fusion of other people’s configuration), you have to include this:

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

    And I don’t know why. But thankfully, with that configuration it works pretty well. I do have a still unsolved problem with file uploads. I still can’t receive file uploads. And I’m still figuring out why.  😖

  • #5 / May 09, 2011 3:18am

    CloudGroup

    2 posts

    If you’re receiving a 404 on codeigniter using nginx, there’s a interesting article here which addresses the re-write rules for nginx

    CodeIgniter NGINX Rewrite Rules

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases