0

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.

1 Answer 1

1

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;

            }
Sign up to request clarification or add additional context in comments.

6 Comments

thanks for your reply. I have updated my code but I still can see 404 error. you can check here likeopedia.net. anything else should I do? here the my sample nginx.conf file: likeopedia.net/nginx.conf
I have updated the answer - see if making the suggested changes help.
Ok I have updated the code again. but same error. Is my fastcgi installed properly? update code looks like following location / { try_files $uri $uri/ /index.php; } 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; }
See if this tutorial here can help: digitalocean.com/community/tutorials/…
Thanks. that was helpful.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.