技术饭

简单配置nginx使之支持pathinfo,解决tp5一直跳转回首页

copylian    0 评论    12953 浏览    2017.11.20

最近是遇到thinkphp5.0.8在nginx环境下不支持pathinfo只支持普通的兼容模式,输入正常的url地址就一直返回首页,测试之后发现是nginx没有配置好pathinfo模式,并且设置了rewrite,通过分析只需要修改3个地方就可以了,亲测成功,看代码有注解。

nginx配置:

location ~ \.php {    #去掉$

     root          H:/PHPServer/WWW;

     fastcgi_pass   127.0.0.1:9000;

     fastcgi_index  index.php;

     fastcgi_split_path_info ^(.+\.php)(.*)$;     #增加这一句

     fastcgi_param PATH_INFO $fastcgi_path_info;    #增加这一句

     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

     include        fastcgi_params;

}

修改后配置:

server {

    listen       80;

    server_name  tp5.com;

    error_page   500 502 503 504  /50x.html;

    root D:/wnmp/www/project/public;

    index  index.php index.html index.htm;


    if (!-e $request_filename) {

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

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

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

        break;

    }

    #之前的配置

    #location ~ \.php$ {

        # fastcgi_pass 127.0.0.1:9001;

        # fastcgi_index index.php;

        # fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        # include        fastcgi_params;

    #}


    location ~ \.php {    #去掉$

         fastcgi_pass   127.0.0.1:9001;

         fastcgi_index  index.php;

         fastcgi_split_path_info ^(.+\.php)(.*)$;     #增加这一句

         fastcgi_param PATH_INFO $fastcgi_path_info;    #增加这一句

         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

         include        fastcgi_params;

    }

}

只袄早~~~
感谢你的支持,我会继续努力!
扫码打赏,感谢您的支持!
thinkphp5 nginx pathinfo 

文明上网理性发言!

  • 还没有评论,沙发等你来抢