Codeigniter nginx 404错误

See*_*hur 3 configuration codeigniter nginx

我不确定此问题已被解答了多少次,但我所看到的每个答案都提供了一种不同的方法来解决这个问题,而这些问题都没有奏效.我正在从Apache迁移到Nginx,并且在设置它时遇到了一些严重的问题.我的/ etc/nginx/sites-available/default看起来像这样......

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www/flo2go/;
    index index.php index.html index.htm;
        if ($request_filename !~ (js|css|images|robots\.txt|index\.php.*) ) {
            rewrite ^/(.*)$ /index.php/$1 last;
        }

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html

                try_files $uri $uri/ /index.php;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
location ~ /index.php/
  {
    include /etc/nginx/fastcgi_params;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/www/flo2go/index.php;
    fastcgi_param  REQUEST_URI      $request_uri;
    fastcgi_param  QUERY_STRING     $query_string;
    fastcgi_param  REQUEST_METHOD   $request_method;
    fastcgi_param  CONTENT_TYPE     $content_type;
    fastcgi_param  CONTENT_LENGTH   $content_length;
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
  }
    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #    # With php5-cgi alone:
    #    fastcgi_pass 127.0.0.1:9000;
    #    # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一切使我的Web应用程序工作.我一直得到的是404:Page Not Found错误.该网站在Apache上完美运行,在花了将近3-4个小时来解决这个问题后,我认为最好在这个论坛上寻求专家的建议.希望有人可以保释我摆脱这种情况:(

小智 7

请在您的配置中添加以下行

if (!-e $request_filename) {
      rewrite ^.*$ /index.php last;
}
Run Code Online (Sandbox Code Playgroud)

这个对我有用


Dmi*_*rov 5

您的情况的正确配置必须与此类似:

server {
    server_name yoursitename.com;
    root /usr/share/nginx/www/flo2go/;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        expires           15d;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/www/flo2go/index.php;
        fastcgi_param  REQUEST_URI      $request_uri;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
     }
}
Run Code Online (Sandbox Code Playgroud)

当前配置的主要问题是2个.php location块,if这是邪恶的.