JokenLiu 发表于 2016-1-25 13:36:07

CI3.0 在 Nginx中 404

server {      server_name www.kenjiaos.com;
      root /home/wwwroot/xiangmu;      index index.html index.php;
      # set expiration of assets to MAX for caching      location ~* \.(ico|css|js|gif|jpe?g|png)(\?+)?$ {                expires max;                log_not_found off;      }
      location / {                # Check if a file or directory index file exists, else route it to index.php.                try_files $uri $uri/ /index.php;      }
      location ~* \.php$ {                fastcgi_pass 127.0.0.1:9000;                include fastcgi.conf;      }}

高飞 发表于 2016-1-25 16:12:09

对于/index.php/abc这种url,Apache和Lighttpd会按”index.php?abc”来解释,而nginx会认为是请求名字是“index.php”的目录下的abc文件的内容。所以CI在nginx下不配置rewrite是无法运行的,而在Apache和Lighttpd则正常。

Nginx里rewrite ^/(.*)$ /index.php?$1 last;来rewrite请求时,对于:/abc.abc这类请求,会rewrite成“index.php/abc_abc”,即会把“点”变成“下划线”,不清楚是为什么。

Nginx配置文件里的rewrite规则不是只执行一次就完事的,是“执行一遍,假如没有碰到break,就按rewrite后的新路径再执行一遍,直到不再变化或者遇到break或者执行满10次报500错误退出”,所以单纯的用小知识二里的重写规则是不行的,需要在后面加上一句break,这样重写一遍后就不再执行了。

Hex 发表于 2016-1-25 13:50:50

是按照 nginx 官方的文档设置的么?

JokenLiu 发表于 2016-1-25 16:03:57

Hex 发表于 2016-1-25 13:50
是按照 nginx 官方的文档设置的么?

是的      加您QQ了

高飞 发表于 2016-1-25 16:09:21

if (!-e $request_filename)
                {   
                        rewrite ^/(.*\.(js|ico|gif|jpg|png|css|bmp|html|xls)$) /$1 last;
                        rewrite ^/(.*) /index.php?$1 last;
                        rewrite ^.*$ /index.php last;
                }   
这段代码加在配置里

洗风 发表于 2016-2-6 10:46:23

本帖最后由 洗风 于 2016-2-6 10:47 编辑

现在的nginx已不要求rewrite,这样改即可:
location / {
               
                try_files $uri $uri/ /index.php?$uri&$args;
      }
页: [1]
查看完整版本: CI3.0 在 Nginx中 404