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 ;
if ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
set $static ;
}
if ($static = ) {
rewrite ^/(.*)$ /index.php?s=/$;
}
}
location ~ /Uploads/.*\.php$ {
deny all;
}
location ~ \.php/ {
if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
fastcgi_pass 127.0.0.1:;
include fastcgi_params;
fastcgi_param SCRIPT_NAME $;
fastcgi_param PATH_INFO $;
fastcgi_param SCRIPT_FILENAME $document_root$;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}

项目完整的 Server 段:

server
{
listen ;
server_name www.tpblog.com;
index index.html index.htm index.php;
root html/www.tpblog.com; #error_page /.html;
include enable-php.conf; location /nginx_status
{
stub_status on;
access_log off;
} #rewrite
location / {
try_files $uri @rewrite;
} location @rewrite {
set $static ;
if ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
set $static ;
}
if ($static = ) {
rewrite ^/(.*)$ /index.php?s=/$;
}
}
location ~ /Uploads/.*\.php$ {
deny all;
}
location ~ \.php/ {
if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
fastcgi_pass 127.0.0.1:;
include fastcgi_params;
fastcgi_param SCRIPT_NAME $;
fastcgi_param PATH_INFO $;
fastcgi_param SCRIPT_FILENAME $document_root$;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
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 配置文件

ThinkPHP3.2.3 Nginx 下 URL_MODEL 的配置的更多相关文章

  1. Nginx下的https配置

    https: https(Secure Hypertext Transfer Protocol) 安全超文本传输协议 它是以安全为目标的http通道,即它是http的安全版.它使用安全套接字层(SSL ...

  2. thinkphp3.2在nginx下的配置

    最近一直没用nginx 昨天将tp3.2的项目部署到Ubuntu下的nginx下,发现忘记怎么配置的了 特将配置方式记录下来,以方便日后查找 服务器nignx 配置文件 server { listen ...

  3. Nginx下Redmine2.6配置

    Apache下Redmine2.6配置,请参考:http://blog.linuxeye.com/405.html CentOS6.6下安装Redmine2.6+MySQL5.6+Nginx,教程如下 ...

  4. nginx下修改svn配置

    最近公司的SVN服务器地址做了变更,而我用的操作系统是Ubuntu操作系统,我也不想把以前下载的代码重新进行修改,我想通过修改svn地址,应该可以,终于在网上通过查找资料,找到了解决的方法:      ...

  5. Yii2项目高级模版 三个模块在同一个目录下的重定向配置

    最近做项目用到的,非常好用. 修改 advanced/backend/config/main.PHP 文件如下: return [ 'homeUrl' => '/admin', 'compone ...

  6. nginx下根据指定路由重定向

    前言: 最近在搭建vue后台,后端接口是PHP写的,线上构建好之后,需要请求其他域名下的接口,开发环境已经使用proxytable解决了接口问题,为了开发和生成的代码一致, 编译后的代码,放在ngin ...

  7. Nginx使用SSL模块配置https

    背景 开发微信小程序,需要https域名,因此使用Nginx的SSL模块配置https 步骤 一.去域名管理商(如腾讯云.阿里云等)申请CA证书 二.在Nginx中配置,一般情况下域名管理商会提供配置 ...

  8. thinkphp3.2.3 + nginx 配置二级域名

    使用的是阿里云centOS.74 第一步: 配置urlpath server { listen ; server_name www.xxxx.com xxxx.com; root /data/www/ ...

  9. 如何在Nginx下配置PHP程序环境

    1.nginx与PHP的关系 首先来看nginx与php的关系, FastCGI的关系(而不是像apache那样安装成nginx的模块) FastCGI的意思是, 快速的通用网关接口:CGI Comm ...

随机推荐

  1. json时间格式化问题

    function jsonDateFormat(jsonDate) {//json日期格式转换为正常格式 try { var date = new Date(parseInt(jsonDate.rep ...

  2. git merge 与 rebase 的区别

    http://gitbook.liuhui998.com/4_2.html merge rebase

  3. HTML DOM domain 属性

    定义和用法 domain 属性可返回下载当前文档的服务器域名. 语法 document.domain 说明 该属性是一个只读的字符串,包含了载入当前文档的 web 服务器的主机名. 提示和注释 提示: ...

  4. sqlmap使用手册

    转自:http://hi.baidu.com/xkill001/item/e6c8cd2f6e5b0a91b7326386 SQLMAP 注射工具用法 1 . 介绍1.1 要求 1.2 网应用情节 1 ...

  5. Java 集合系列18之 Iterator和Enumeration比较

    概要 这一章,我们对Iterator和Enumeration进行比较学习.内容包括:第1部分 Iterator和Enumeration区别第2部分 Iterator和Enumeration实例 转载请 ...

  6. Android入门第八篇之GridView(九宫图)

    本文来自http://blog.csdn.net/hellogv/ GridView跟ListView都是比较常用的多控件布局,而GridView更是实现九宫图的首选!本文就是介绍如何使用GridVi ...

  7. ACM: HDU 1028 Ignatius and the Princess III-DP

     HDU 1028 Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Form ...

  8. jQuery自定义滚动条样式插件mCustomScrollbar

    如果你构建一个很有特色和创意的网页,那么肯定希望定义网页中的滚动条样式,这方面的 jQuery 插件比较不错的,有两个:jScrollPane 和 mCustomScrollbar. 关于 jScro ...

  9. Fedora 23 配置

    Linux下安装Fedora 刻到u盘上 下好iso后准备刻录到u盘...可是查了一下只能在用一个叫dd的东西刻= =于是学了下...然而就是一句话: dd if=/path/xxx.iso of=/ ...

  10. XCode编译文件过多导致内存吃紧解决方法

    XCode编译文件过多导致内存吃紧解决方法 /Users/~~/Library/Developer/Xcode/DerivedData 1) 然后 找到编译文件 删除 就好了哦 快去试试看吧