荆轲刺秦王

首先tp5的访问目录指向到webroot/public文件夹中。

thinkphp的url访问:http://serverName/index.php(或者其它应用入口文件)/模块/控制器/操作/[参数名/参数值...],这个需要支持pathinfo,Apache默认支持,而Nginx不支持。

1.php.ini中的配置参数cgi.fix_pathinfo = 1

find / -name php.ini

vim /etc/php.ini

/cgi.fix

Esc :noh
:wq

2.修改nginx.conf文件。

location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;

            #下面两句是给fastcgi权限,可以支持 ?s=/module/controller/action的url访问模式
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            #下面两句才能真正支持 index.php/index/index/index的pathinfo模式
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

这样就能在linux,nginx环境下运行tp5了。

3. 伪静态 去掉/index.php/

修改nginx.conf文件:

location / {
    index  index.html index.htm index.php;
    #autoindex  on;
            
    if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
    }
}

至此已经全部完成。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐