Part of the EllisLab Network
   
 
CodeIgniter Nginx Rewrite Rule
Posted: 08 December 2008 12:43 PM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  248
Joined  11-08-2007

Thought this might of some use to some of you.

server {
    
    listen   80
;
    
    
root /var/www/nginx-default/;
    
access_log  /var/log/nginx/localhost.access.log;
    
index index.php index.html index.htm;

    
error_page 500 502 503 504  /50x.html;

    
location /codeigniter{
        
        
if (-f $request_filename{
            expires max
;
            break;
        
}
    
        
if (!-e $request_filename{
            rewrite 
^/codeigniter/(.*)$ /codeigniter/index.php/$1 last;
        
}
    }
    
    location 
= /50x.html {
        root 
/var/www/nginx-default;
    
}

    location 
/codeigniter/index.php {
        fastcgi_pass 127.0.0.1
:9000;
        
fastcgi_index index.php;
        
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default/codeigniter/index.php;
        include 
fastcgi_params;
    
}

The rules inside the location directive basically says : if the file exists then set the maximum expiration date and output it. This is usually css, images, js, etc ...

Then the second rules states that if the file doesn’t exist then we assume it’s a codeigniter url and redirect the request to the index.php file with the request string.

 Signature 

Redux Auth is no longer maintained.

Profile
 
 
Posted: 20 July 2010 01:57 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  40
Joined  11-14-2008

I recently wrote some rewrite rules for nginx, thought I’d also share:  CodeIgniter NGINX Rewrite Rules...

 Signature 

CodeIgniter htaccess
Web Development
Blogging Topics - Table of Contents
Follow me on twitter

Profile
 
 
Posted: 29 September 2010 08:37 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  10
Joined  12-28-2009

Worth mentioning is to set the URI protocol to “REQUEST_URI” or “AUTO” I suppose in order to use codeigniter with nginx.

Profile
 
 
Posted: 16 May 2011 12:06 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  1
Joined  05-16-2011
farinspace - 20 July 2010 05:57 PM

I recently wrote some rewrite rules for nginx, thought I’d also share:  CodeIgniter NGINX Rewrite Rules...

Awesome article!  There was a lot of CodeIgniter-specific configuration that I had missed.  Thanks for that.

Profile