CodeIgniter Forums
CodeIgniter Nginx Rewrite Rule - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: CodeIgniter Nginx Rewrite Rule (/showthread.php?tid=13843)



CodeIgniter Nginx Rewrite Rule - El Forum - 12-08-2008

[eluser]Popcorn[/eluser]
Thought this might of some use to some of you.
Code:
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.


CodeIgniter Nginx Rewrite Rule - El Forum - 07-20-2010

[eluser]farinspace[/eluser]
I recently wrote some rewrite rules for nginx, thought I'd also share: CodeIgniter NGINX Rewrite Rules...


CodeIgniter Nginx Rewrite Rule - El Forum - 09-29-2010

[eluser]mptre[/eluser]
Worth mentioning is to set the URI protocol to "REQUEST_URI" or "AUTO" I suppose in order to use codeigniter with nginx.


CodeIgniter Nginx Rewrite Rule - El Forum - 05-16-2011

[eluser]Unknown[/eluser]
[quote author="farinspace" date="1279666668"]I recently wrote some rewrite rules for nginx, thought I'd also share: CodeIgniter NGINX Rewrite Rules...[/quote]

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


CodeIgniter Nginx Rewrite Rule - El Forum - 08-17-2012

[eluser]bonatoc[/eluser]
What about using nginx as a reverse proxy ?

What would be the only rules to keep ?