Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Nginx Rewrite Rule
#1

[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.
#2

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

[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.
#4

[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.
#5

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

What would be the only rules to keep ?




Theme © iAndrew 2016 - Forum software by © MyBB