Thinkphp Nginx下的配置

 最近公司需要使用Thinkphp来做一个项目。开始为了方便,我选择了,apache的集成包。并配置了URL_MODEL=2,一切工作正常。
 本地开发结束后需要将项目迁移到服务器,但服务器使用的是nginx。迁移之后发现apache下正常的功能都无法使用。nginx不支持Thinkphp 的工作模式

Windows下

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #这里是对URL的路径的解析,以及处理。
        #
        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        #如果只是简单的使用php,我们需要将这里注释掉.
        # 这里配置当路径中包含.php的时候,将会交由php的CGI进行处理。
        #所以我们在使用,跟姐此时必须先启动php的CGI服务器
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

更改为:


 location / {
            root   html;
            index  index.html index.htm;
            #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
            if (!-e $request_filename)
            {
                #地址作为将参数rewrite到index.php上。
                #rewrite ^/(.*)$ /index.php/$1;
                #若是子目录则使用下面这句,将subdir改成目录名称即可。例如我的子项目名入口文件为localhost/abc/index.php,这里为
                rewrite ^/abc/(.*)$ /abc/index.php/$1;
                #如果还有另一个子项目,入口文件为localhost/test/efg/index.php,则为
                rewrite ^/test/eft/(.*)$ /test/eft/index.php/$1;
            }
        }


    #去掉$是为了不匹配行末,即可以匹配.php/,以实现pathinfo
    #如果你不需要用到php5后缀,也可以将其去掉
    location ~ .php
        {
                #原有代码

                #定义变量 $path_info ,用于存放pathinfo信息
                set $path_info "";
                #定义变量 $real_script_name,用于存放真实地址
                set $real_script_name $fastcgi_script_name;
                #如果地址与引号内的正则表达式匹配
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                        #将文件地址赋值给变量 $real_script_name
                        set $real_script_name $1;
                        #将文件地址后的参数赋值给变量 $path_info
                        set $path_info $2;
                }
                #配置fastcgi的一些参数
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
        }

之后重新加载下配置文件, nginx -s reload

Linux下在CGI略有不同

#fastcgi_pass 127.0.0.1:9000; // pass 不是这个
fastcgi_pass unix:/dev/shm/php-cgi.sock; // 而是这个或者
fastcgi_pass unix:/xxx/xxx/php-cgi.sock //视情况而定.参考默认。

原文参考在这里:http://www.thinkphp.cn/topic/3138.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值