我不确定此问题已经回答了多少次,但我看到的每个答案都提供了一种不同的方法来解决这个问题,而这些问题都没有奏效。我正在从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;
}
}
我已经尝试了一切来使我的Web应用程序正常工作。我一直得到的是404:Page Not Found错误。该网站在Apache上完美运行,在花了将近3-4个小时来解决这个问题后,我认为最好在这个论坛上寻求专家的建议。希望有人可以帮我摆脱这种情况:(
答案 0 :(得分:6)
请在您的配置中添加以下内容
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
它对我有用
答案 1 :(得分: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;
}
}
当前配置的主要问题是2个.php location
块和if
evil。
答案 2 :(得分:1)
检查控制器,视图,模型和数据库的命名。
如果您在控制器中执行此操作:
$this->load->view('main');
然后视图的文件名必须与您在控制器中编写的文件名相同:
main.php
答案 3 :(得分:1)
nginx比文件名更加挑剔。
我的控制器名为Proto,名为proto.php
。我将其重命名为Proto.php
并开始工作。
Nginx对控制器文件名的情况很敏感。