首页 > 后端开发 > php教程 > Nginx+CI出现404错误,nginxci404错误_PHP教程

Nginx+CI出现404错误,nginxci404错误_PHP教程

WBOY
发布: 2016-07-12 08:58:01
原创
910 人浏览过

Nginx+CI出现404错误,nginxci404错误

最近刚学ci框架,做了个简单的项目,在本地搭服务器的环境都调通了,但是部署到远程服务器时:

 

http://example.com/(index.php)/ 可以访问(为配置的默认controller-class)

http://example.com/(index.php)/[controller-class]/[controller-method] 不可以访问(提示404错误!)

 

最后百度原因:

对于/index.php/abc这种url,Apache和Lighttpd会按”index.php?abc”来解释,而nginx会认为是请求名字是“index.php”的目录下的abc文件的内容。所以CI在nginx下不配置rewrite是无法运行的,而在Apache和Lighttpd则正常。   解决方案(要点加,重点标):
<span> 1</span> <span>  server {
</span><span> 2</span>         listen 80<span>;
</span><span> 3</span>         server_name <strong>example.com</strong><span>;
</span><span> 4</span>         root <strong>/data/wwwroot/example/</strong><span> 5</span>         index index.php index.html index.<span>htm;
</span><span> 6</span> 
<span> 7</span>         location ~* \.(css|js|swf|htm|jpg|png|gif|json|atlas)?<span>$ {
</span><span> 8</span> <span>            expires 1d;
</span><span> 9</span>             add_header Pragma <span>public</span><span>;
</span><span>10</span>             add_header Cache-Control "public"<span>;
</span><span>11</span> <span>        }
</span><span>12</span>         
<span>13</span>         location /<span><strong>controller-class</strong></span>/<span> {
</span><span>14</span>             <span>if</span> (!-e <span>$request_filename</span><span>) {
</span><span>15</span>                 rewrite ^/<span><strong>controller-class</strong></span>/(.*)$  /<strong><span>controller-class</span></strong>/index.php?q=<span>$uri</span>&<span>$args</span><span>;
</span><span>16</span> <span>            }
</span><span>17</span> <span>        }
</span><span>18</span>  
<span>19</span>         location ~ \.<span>php$ {
</span><span>20</span>             fastcgi_pass   127.0.0.1:9000<span>;
</span><span>21</span>             fastcgi_index  index.<span>php;
</span><span>22</span>             fastcgi_param  SCRIPT_FILENAME  <span>$document_root$fastcgi_script_name</span><span>;
</span><span>23</span>                         fastcgi_param  PHP_VALUE        open_basedir=<span>$document_root</span>:/tmp/:/proc/<span>;
</span><span>24</span>             <span>include</span><span>        fastcgi_params;
</span><span>25</span> <span>        }
</span><span>26</span> 
<span>27</span>     }
登录后复制

 

参考资料:http://www.2cto.com/os/201301/185926.html【Nginx+CI出现404错误问题】

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1105554.htmlTechArticleNginx+CI出现404错误,nginxci404错误 最近刚学ci框架,做了个简单的项目,在本地搭服务器的环境都调通了,但是部署到远程服务器时: http:...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板