Nginx,Codeigniter 404错误。无法访问index.php文件

时间:2016-07-23 18:23:52

标签: nginx configuration codeigniter-2

我试图在线找到解决方案,但每个解决方案都不同。没有人在工作。我刚刚将我们的Web服务器从Apache迁移到Nginx,我收到404错误。这是php信息:http://likeopedia.net/info.php。如果您访问主域,则会看到错误。

我正面临着一些严重的问题。我们的网站正在使用Apache服务器,但不在Nginx上。

这里是我已经改变了一点的nginx.conf文件。

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;
        }

这里是codeigniter confiq.php文件:

$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'] = '';

现在处于开发模式。

1 个答案:

答案 0 :(得分:1)

您已将location = /index.php括在location /内。请尝试更改location /,使其不包含location = /index.php。 它应该是这样的:

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;
  }

尝试一下,如果有帮助,请告诉我们。 感谢您的反馈 - 以下是我认为您也可以尝试的内容: 移除location = /index.php,然后尝试location ~\.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;

            }