Main menu

NginX configuration for codigniter or laravel

I have installed Codigniter, laravel like project many times in Apache, but when it’s come to NginX it’s may tricky becaue there are not .htaccess redirects. All things you have to put on NginX configuration file.

Here is my NginX config file which i have put in my /etc/nginx/conf.d/my.conf for my CodeIgniter project.

    access_log /var/log/nginx/;
    root /home/myapp/domains/;
    index index.php index.html index.htm;

    if ($request_uri ~* index/?$)
    rewrite ^/(.*)/index/?$ /$1 permanent;

    error_page 404 /index.php;

# Proxy to PHP-FPM for PHP Execution
    location ~ \.php$
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/myapp/domains/$fastcgi_script_name;
    include fastcgi_params;
# deny access to apache .htaccess files
    location ~ /\.ht
        deny all;

Here is a quick link for converting .htaccess rules to NginX configuration

Notes: Navigate to your “/system/application/config/config.php” file and set the $config[‘index_page’] = “”; so index.php will be remove form your URL.