zoukankan      html  css  js  c++  java
  • ThinkPHP3.2.3 Nginx 下 URL_MODEL 的配置

    ThinkPHP3.2.3 的 URL_MODEL 包括普通模式(0)、PATHINFO 模式(1)、REWRITE 模式(2)、兼容模式(3)等 4 种 URL 模式。在 Apache 下只要在配置文件 config.php 中配置 URL_MODEL 配合 .htaccess 就可以很容易地支持 REWRITE 模式。

    在 Nginx 下设置项目的 URL 模式可以参考 老朱亲自写的,最完美ThinkPHP Nginx 配置文件,支持以上 4 种 URL 模式。

    我测试的环境是 CentOS 6.6 + LNMP 1.2 (Nginx 1.8.0,MySQL5.6.23,PHP 5.6.9)+ ThinkPHP 3.2.3

    编辑 nginx.conf 文件:

    [root@localhost conf]# vim nginx.conf

    在项目的 Server 段中加入:

        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 ~ /Uploads/.*.php$ {
            deny all;
        }
        location ~ .php/ {
           if ($request_uri ~ ^(.+.php)(/.+?)($|?)) { }
           fastcgi_pass 127.0.0.1:9000;
           include fastcgi_params;
           fastcgi_param SCRIPT_NAME     $1;
           fastcgi_param PATH_INFO       $2;
           fastcgi_param SCRIPT_FILENAME $document_root$1;
        }
        location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }

    项目完整的 Server 段:

    server
    {
            listen 80;
            server_name www.tpblog.com;
            index index.html index.htm index.php;
            root  html/www.tpblog.com;
    
            #error_page   404   /404.html;
            include enable-php.conf;
    
            location /nginx_status
            {
                stub_status on;
                access_log   off;
            }
    
            #rewrite
            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 ~ /Uploads/.*.php$ {
                    deny all;
            }
            location ~ .php/ {
                    if ($request_uri ~ ^(.+.php)(/.+?)($|?)) { }
                    fastcgi_pass 127.0.0.1:9000;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_NAME     $1;
                    fastcgi_param PATH_INFO       $2;
                    fastcgi_param SCRIPT_FILENAME $document_root$1;
            }
            location ~ .php$ {
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }
            location ~ /.ht {
                    deny  all;
            }
            #rewrite结束
    
            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
    
            location ~ .*.(js|css)?$
            {
                expires      12h;
            }
    
            location ~ /.
            {
                deny all;
            }
                    access_log  /home/wwwlogs/access_tpblog.log  access;
    
    }

    参考:老朱亲自写的,最完美ThinkPHP Nginx 配置文件

  • 相关阅读:
    加密算法 科普文
    《电商后台系统产品逻辑解析》学习笔记
    基于Docker的Consul服务发现集群搭建
    从阿里中台战略看企业IT架构转型之道
    CanalSharp.AspNetCore v0.0.4-支持输出到MongoDB
    领域驱动设计学习之路—DDD的原则与实践
    一个实时收集MySql变更记录的组件CanalSharp.AspNetCore
    基于Jenkins Pipeline的ASP.NET Core持续集成实践
    熊逸《唐诗50讲》感时篇
    一个Mini的ASP.NET Core框架的实现
  • 原文地址:https://www.cnblogs.com/dee0912/p/5208002.html
Copyright © 2011-2022 走看看