• tp3.23 nginx lnmp填坑


    thinkphp3.23在apache上可以轻松实现4个路由模式

    但是在nginx上就出现问题

    我们的环境是用lnmp包实现(地址:https://lnmp.org/)

    安装完成后,ta的lnmp的nginx是默认在 /usr/local/nginx(linux)

    在/usr/local/nginx/conf下,我们发现有个thinkphp.conf文件

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

    如果我们用这个配置站点可以实现:

    http://test.cc/home/index/index

    但是如果要用:

    http://test.cc/index.php/home/index/index

    不能成功。

    我们可以新建一个tp3.23.conf的配置文件

    location / {
        try_files $uri @rewrite;
    }
    
    location @rewrite {
        set $static 0;
        if  ($uri ~ .(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css.map|min.map)$) {
                set $static 1;
        }
        if ($static = 0) {
                rewrite ^/(.*)$ /index.php?s=/$1;
        }
    }
    location ~ .php/ {
            if ($request_uri ~ ^(.+.php)(/.+?)($|?)) { }
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            include fastcgi_params;
            fastcgi_param SCRIPT_NAME     $1;
            fastcgi_param PATH_INFO       $2;
            fastcgi_param SCRIPT_FILENAME $document_root$1;
    }
    location ~ .php$ {
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    那vhost如下

    server
    {
        listen 80;
        server_name test.cc ;
        index index.html index.htm index.php;
        root  /home/wwwroot/tp3.23;
    
        #error_page   404   /404.html;
        
    
        #rewrite
        include tp3.23.conf;
        location ~ /.ht {
                deny  all;
        }
        #rewrite结束
    
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
    
        location ~ .*.(js|css)?$
        {
            expires      12h;
        }
    
        location ~ /.
        {
            deny all;
        }
    
    }

    如上就可以实现

    http://test.cc/home/index/index 与 http://test.cc/index.php/home/index/index

    参考:

    https://lnmp.org/faq/lnmp-vhost-add-howto.html

    https://www.cnblogs.com/dee0912/p/5208002.html

    http://www.thinkphp.cn/topic/34380.html

  • 相关阅读:
    类对象成员函数的const增强zz
    希腊与罗马神话神名对照
    c++程序调用c函数 and otherwise zz
    百度相信中国电子书下载
    VolatileCorrectness,让编译器帮你检测竞争条件 zz
    高效计算一个bytes有几个byte是1?
    实现mybatis官网入门实例
    Windows Phone 深度探索(一) 带有(伪)元素加载动画的Panel (SlideInPanel)
    You have asked for this, it is basically your fault!
    New EC2 Instance Types of re:Invent 2021
  • 原文地址:https://www.cnblogs.com/lmaster/p/8613429.html
Copyright © 2020-2023  润新知