码迷,mamicode.com
首页 > Web开发 > 详细

配置nginx支持thinkphp框架

时间:2016-01-22 02:52:44      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

因为nginx本身没有支持pathinfo,所以无法使用thinkphp框架,不过我们可以在配置里进行修改使其能够正常使用thinkphp。

1.修改配置支持pathinfo

vi /etc/nginx/cong.d/default.conf

在nginx的配置中添加

location ~ \.php/?.*$ {
      root html;         #这里的路径需要注意一下,自己之前几次配置错误都是因为从网上直接粘贴的路径不对
        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index  index.php;  
        include        fastcgi.conf;  
                  
        set $fastcgi_script_name2 $fastcgi_script_name;  
        if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {  
            set $fastcgi_script_name2 $1;  
            set $path_info $2;  
        }  
        fastcgi_param   PATH_INFO $path_info;  
        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;  
        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;  
    } 

重启nginx,service nginx restart

测试:

修改好了配置之后我们来测试一下

vi /usr/share/nginx/html/think/Application/Home/Controller/IndexController.class.php修改一下控制器文件

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $this->display();

}
}

再建立模板文件,vi /usr/share/nginx/html/think/Application/Home/View/Index/index.html
随便写一点内容:hello,world

访问地址:###/think/index.php/Home/Index/index.html

显示出hello,world的话,说明配置成功

 

2.我们在thinkphp框架的使用中经常会用到url重写模式,所以我们再配置一下rewrite

location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
           rewrite  ^/(.*)$  /index.php/$1  last;
           break;
        }  
        # example
        #ModSecurityEnabled on;
        #ModSecurityConfig /etc/nginx/modsecurity.conf;
    }
重启nginx

配置nginx支持thinkphp框架

标签:

原文地址:http://www.cnblogs.com/isuifeng/p/5149953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!