Konfigurasi Nginx untuk Code Igniter

Konfigurasi untuk nginx sebetulnya sangat mudah. Tapi bagaimana caranya menghilangkan index.php dari code igniternya.
3973  
       

Konfigurasi mod_rewrite Code Igniter untuk nginx sebetulnya sangat mudah. Tapi bagaimana caranya menghilangkan index.php dari code igniternya.

Berikut ini adalah caranya.

Pengaturan Nginx

Tambahkan kode ini di block server { .. }.
Biasanya pengaturan nginx ini ada di /etc/nginx/conf.d/ untuk centos versi 6.x atau bisa juga disesuaikan.

server {
        server_name domain.tld;

        root /var/www/codeignitor;
        index index.html index.php;

        # set expiration of assets to MAX for caching
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

        location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri $uri/ /index.php;
        }

        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi.conf;
        }
}

Kemudian untuk pengaturan konfigurasi di Code Igniter-nya adalah sebagai berikut:

$config['base_url'] = "https://www.nyingspot.com/";
$config['index_page']       = "";
$config['uri_protocol']     = "REQUEST_URI";

Hilangkan index.php dibagian index page.
Demikian. Semoga membantu.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>