我使用Nginx和Codeigniter以及php5-fpm。一切似乎“工作得很好,页面显示,一切都很好。这不是我在这里问这个问题的原因,我确实有一个问题。页面显示正常,但Nginx日志显示“File not found”
我面临的问题是404错误与页面引发,即使页面呈现正常,我仍然404(在日志中)。
为什么我得到404的(之后看Nginx的错误日志),是Nginx无法打开我请求的文件,因为Nginx试图直接打开PHP文件,而不是参考controller/method
,不幸的是Codeigniter的工作方式。
例如:
请求http://website.com/<controller>/<function>/<other_params>
导致404 Nginx的日志,这背后的原因是,open()
无法打开指定的目录,因为不存在的话,而不是指controller/method
。
一些重要的日志:
Nginx的错误日志:
[error] 4172#0: *482 open() "/var/www/<domain>/public/site/section/main" failed
(2: No such file or directory), client: <client_ip>, server: <domain>, request: "GET
/site/section/main HTTP/1.1", host: "<domain>"
正如我以前说过,Nginx的试图直接访问的,而不是使笨处理它的文件。
我sites-enabled/ci
配置:
server
{
server_name <domain> *.<domain>;
access_log /var/www/<domain>/access.log;
error_log /var/www/<domain>/error.log;
root /var/www/<domain>/public;
index index.php index.html index.htm;
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
# enforce www (exclude certain subdomains)
# if ($host !~* ^(www|subdomain))
# {
# rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
# }
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/site(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$/permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
# if (!-d $request_filename)
# {
# rewrite ^/(.+)/$ /$1 permanent;
# }
# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/(system|application))
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
#if (!-e $request_filename)
#{
# rewrite ^/(.*)$ /index.php?/$1 last;
# break;
#}
# catch all
error_page 404 /index.php;
# use fastcgi for all php files
location ~ \.php($|/)
{
#if (!-e $request_filename) {
# return 404;
# }
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass php5-fpm-sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# location/{
# try_files $uri $uri/ @codeigniter;
#}
# location @codeigniter {
# rewrite ^(.*) /index.php?$1 last;
# }
# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}
那么,什么是Nginx的和笨之间的这种误解背后的原因是什么?
在此先感谢。