最近研究CI框架,发现这个框架的路由功能在Nginx下有问题,报404错误,后来在网上查资料,
发现需要开启PATH_INFO。在nginx7.16以后貌似就支持PATH_INFO了,只需要在配置文件中开启即可。
打开nginx.conf文件,在你的虚拟主机下增加重写规则,代码如下:
server {
<wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">listen</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">80;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">server_name</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">www.ci.com;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">location / {<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">root</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">d:/www/Codeigniter_2.0.1/;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">index</span><wbr><span style="font-size:18px"> index.html index.htm index.php;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"> rewrite ^/$/index.php last;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"> rewrite^/(?!index\.php|robots\.txt|images|js|styles)(.*)$ /index.php/$1last;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">}<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"> location ~^(.+\.php)(.*)$ {<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">root</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">D:/www/Codeigniter_2.0.1/;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">fastcgi_index</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">index.php;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">fastcgi_split_path_info ^(.+\.php)(.*)$;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">fastcgi_param</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">SCRIPT_FILENAME</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">$document_root$fastcgi_script_name;<br><span style="color:rgb(255,0,0)"></span></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)">fastcgi_param</span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)">PATH_INFO</span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px; color:rgb(255,0,0)"></span><wbr style="color:rgb(255,0,0)"><span style="font-size:18px"><span style="color:rgb(255,0,0)">$fastcgi_path_info;</span><br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">fastcgi_param</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">PATH_TRANSLATED</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">$document_root$fastcgi_path_info;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">fastcgi_pass</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">127.0.0.1:9002;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">include</span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px">fastcgi_params;<br></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"></span><wbr><span style="font-size:18px"> }<br> }</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>