NGINX configuration for CodeIgniter 2.0

NGINX configuration for CodeIgniter 2.0

This is my NGINX configuration for running CodeIgniter 2.0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
server {

    listen   80; ## listen for ipv4

    server_name ci;
    root        /your-public-html;
    access_log  /var/log/nginx/yourdomain.access.log;
    error_log  /var/log/nginx/yourdomain.error.log;

    # If file is an asset, set expires and break
    location ~* .(ico|xml|gz|xml.gz|css|js|gif|jpe?g|png)(?[0-9]+)?$ {
        expires max;
        break;
    }

    location / {
        index  index.php index.html index.htm;

        if (-f $request_filename) {
            expires 30d;
            break;
        }

        if (!-e $request_filename) {
            rewrite ^(.+)$ /index.php?$1 last;
            break;
        }

    }

    location ~ .php$ {
        fastcgi_send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_connect_timeout 1800;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /your-public-html/$fastcgi_script_name;
        include fastcgi_params;
    }


    location ~ /.ht {
        deny  all;
    }
}

@kudos to Buclar :
If you get some problem, then you should set uri_protocol to $config[‘uri_protocol’] = ‘REQUEST_URI’;

Leave a Reply

Your email address will not be published. Required fields are marked *