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.

server
{
    server_name app.myapp.com;
    access_log /var/log/nginx/app.myapp.com.access.log;
    root /home/myapp/domains/app.myapp.com/public_html;
    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_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/myapp/domains/app.myapp.com/public_html$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.

FacebookTwitterGoogle+RSS