如何配置Nginx支持TP框架的PATHINFO

2026-02-27 16:46:16

1、现在网上个人用的云服务器都是nginx,但是nginx默认又不支持TP的重写模式,拿百度的BCH虚拟主机举个例子。

2、项目放上去以后,如果用 域名/admin会直接提示404找不到文件

3、我们没有权限直接修改nginx.cof,我们在webroot目录下添加一个bcloud_nginx_user.conf,写上如下代码,注意if和括号之间有空格 要不然不能生效的。

4、location / { // …..省略部分代码

  if (!-e $request_filename) {

  rewrite  ^(.*)$  /index.php?s=$1  last;

  break;

   }

}

如果你的ThinkPHP安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。

location /youdomain/ {

   if (!-e $request_filename){

       rewrite  ^/youdomain/(.*)$  /youdomain/index.php?s=$1  last;

   }

}

将文件上传之后重启服务器就可以了

相关推荐
  • 阅读量:169
  • 阅读量:170
  • 阅读量:33
  • 阅读量:184
  • 阅读量:93
  • 猜你喜欢