修改Nginx解决ThinkPHP不支持PathInfo模式

最精简的Nginx配置

server {
        listen       80;
        server_name  test.com;
        charset utf-8;

        location / {
            root   E:/WWW/test;
            index  index.php;

            if (!-e $request_filename) {
                #一定要用(.*)匹配整个URI,包含URI第一个字符反斜杠/
                #rewrite ^(.*)$ /index.php?s=$1 last;
                rewrite  ^/(.*)index.php(.*)$  $1/index.php?s=$2  last;
                break;
            }
        }

        location ~ \.php$ {
            root           E:/WWW/test;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

关键就是,高级版的:

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

1、精简版的:PathInfo模式http://test.com/index.php/home/wendang/index,会报错无法找到模板index.php,其他正常

2、高级版的:貌似这种,兼容模式http://test.com/home/wendang/index,会出现Not Found,其他正常

参考:nginx解决ThinkPHP PATHINFO不支持问题

原文地址:https://www.cnblogs.com/sanplit/p/8135708.html

时间: 2024-08-07 23:07:15

修改Nginx解决ThinkPHP不支持PathInfo模式的相关文章

nginx低版本不支持pathinfo模式,thinkphp针对此问题的解决办法

将一个thinkphp项目从apache环境移到nginx1.2上,怎奈,nginx这个版本默认不支持pathinfo模式 首先,编辑nginx的虚拟主机配置文件 location ~ .*.(php|php5)?$ { #原有代码 } if (!-e $request_filename) {   rewrite  ^(.*)$  /index.php?s=$1  last;   break;    } #去掉$是为了不匹配行末,即可以匹配.php/,以实现pathinfo #如果你不需要用到p

配置Nginx支持pathinfo模式

Nginx服务器默认不支持pathinfo, 在需要pathinfo支持的程序中(如thinkphp),则无法支持”/index.php/Home/Index/index”这种网址.网上流传的解决办法很多,这里提供一种比较简洁的写法(只需要改动2行代码)典型配置location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $DOC

LNMP一键安装包+Thinkphp搭建基于pathinfo模式的路由(可以去除url中的.php)

LNMP一键安装包是一个用Linux Shell编写的可以为CentOS/RadHat/Fedora.Debian/Ubuntu/Raspbian/Deepin VPS或独立主机安装LNMP(Nginx/MySQL/PHP).LNMPA(Nginx/MySQL/PHP/Apache).LAMP(Apache/MySQL/PHP)生产环境的Shell程序.同时提供一些实用的辅助工具如:虚拟主机管理.FTP用户管理.Nginx.MySQL/MariaDB.PHP的升级.常用缓存组件Redis.Xca

nginx不支持pathinfo模式解决方法

错误描述:1,打开网页,页面提示不支持pathinfo                  2,类似 index.php/hellworld 会提示找不到页面 解决办法:1,修改nginx.conf的server{} 中的内容下: 备注: 如果是在vhost配置下可单独添加在vhost配置文件下,如果没有vhost则在nginx.conf配置文件下添加 75         # pass the PHP scripts to FastCGI server listening on 127.0.0.

nginx+thinkphp下解决不支持pathinfo模式以及存在的各种404,500问题

nginx环境问题弄了两天,发现网上很多人的帖子要么复制粘贴,要么就是没有结贴,还自己写一句“哈哈,我自己解决了”之类的,这点我就鄙视这些发帖的同胞了,你说你问题问了,问题解决了也不给个解释.还在搜索的前几页,想没想过需要答案的人的感受呢.满心欢喜的去看答案,发现没有结贴.好吧,不多说,进入正题. 我这种方式是不需要将URL_Model改为rewrite/兼容的: 大约第43行,按照下面的对照自己的code进行修改,请注意细节的符号: location / {            root  

nginx下TP5 隐藏入口文件+支持pathinfo模式+配置多项目根目录

首先说下项目目录情况  跟目录/usr/share/nginx/html/(别说怎么这么深  0.0) html文件夹下面两个目录 pssh  pssh_shop 两个tp5项目分别对应两个二级域名 配置多项目就把server{} 在复制出来一套 修改对应的root路径就可以 下面放上配置文件(只有域名2那个项目隐藏入口文件了 ) # For more information on configuration, see: # * Official English Documentation: h

(亲测)nginx解决thinkphp中pathinfo的问题

找到nginx配置文件中的location ~ \.php$ 去掉后面的"$" 在中括弧里的最下面添加: fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 加号的代码如下面: location ~ \.php {         

配置nginx1.7.8支持pathinfo模式

vi nginx/conf/nginx.conf 1.修改正则 set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){ set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_pa

lnmp1.0支持pathinfo模式

首先,在ssh中执行 touch /usr/local/nginx/conf/pathinfo.conf 创建pahtinfo.conf文件 然后在这个文件中添加以下内容 set $real_script_name $fastcgi_script_name;if ($fastcgi_script_name ~ "(.+?\.php)(/.*)") {set $real_script_name $1;set $path_info $2;}fastcgi_param SCRIPT_FILE