Mijanur Rahaman
Mijanur Rahaman

Reputation: 3

Nginx, Codeigniter 404 error. Can't access index.php file

I tried to find out the solution online but every solution is different. no one is working. I just migrated our web server from Apache to Nginx and I am getting 404 error. Here is the php info: http://likeopedia.net/info.php. If you visit main domain then you will see the error.

I am facing some serious problems for this setup. Our site is working on Apache server but not on Nginx.

here is nginx.conf file that I have changed a little bit.

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;
    autoindex on;
    index index.php;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root        /var/www/html;

        include /etc/nginx/default.d/*.conf;
        index index.php index.html index.htm;
        rewrite_log on;
        location / {
         try_files $uri $uri/ /index.php;

         location = /index.php {

                        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
                        fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
                        include        fastcgi_params;
                    }
        }   

      location ~ \.php$ {
            return 444;
        }

and here the codeigniter confiq.php file:

$config['base_url'] = 'http://likeopedia.net';

$config['abs_path'] = $_SERVER['DOCUMENT_ROOT'].'/';

$config['logout_url']   = 'http://likeopedia.net';

$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO';

$config['url_suffix'] = '';

It is now in development mode.

Upvotes: 0

Views: 2208

Answers (1)

ishmaelMakitla
ishmaelMakitla

Reputation: 3812

You have enclosed the location = /index.php inside the location /. Try changing the location / so that it does not enclose location = /index.php. It should look like this:

location / {
         try_files $uri $uri/ /index.php;
        }   
location = /index.php {
          fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
          fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
          include        fastcgi_params;
        }
location ~ \.php$ {
    return 444;
  }

Give it a try and let us know if this helps. Thank for the feedback - here is what I think you can try as well: Remove the location = /index.php and instead try the following configuration for the location ~\.php$ declarative:

location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                    include fastcgi_params;

            }

Upvotes: 1

Related Questions