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. 20145223《Java程序程序设计》实验报告5

    20145223杨梦云<Java网络编程> 一.实验内容 ·1.运行下载的TCP代码,结对进行,一人服务器,一人客户端: ·2.利用加解密代码包,编译运行代码,一人加密,一人解密: ·3. ...

  2. 获取DLL中的方法名称

      OpenFileDialog obj = new OpenFileDialog(); if (obj.ShowDialog() == System.Windows.Forms.DialogResu ...

  3. jqgrid在colModel中多次调用同一个字段值

    Debug: 代码1: { name : 'input', index : 'input', width : 100, align : "center", formatter : ...

  4. iOS学习28之UITabBarController

    1. 标签视图控制器 -- UITabBarController 视图(UIView) ---> 图层 ---> 子视图 视图控制器(UIViewController) ---> 管 ...

  5. 连连看[HDU1175]

    连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. 在SUBLIME TEXT中安装SUBLIMELINTER进行JS&CSS代码校验

    一:Sublime Text 中需要先安装Package Control.(如果有则无需安装) 安装方法:打开Sublime Text控制台(快捷键Ctrl+`),在控制台粘贴以下代码,按回车执行. ...

  7. Web标准中用于改善Web应用程序性能的各种方法总结

    提起Web应用程序中的性能改善,广大开发者们可能会想到JavaScript与DOM访问等基于各种既存技术的性能改善方法.最近,各种性能改善方法被汇总成为一个Web标准. 本文对Web标准中所包含的各种 ...

  8. float浮动问题:会造成父级元素高度坍塌;

    float浮动问题:会造成父级元素高度坍塌: 解决办法:清除浮动:clear:both; 给父元素高度:height(不是很可取) 给父元素:display:inline-black:(问题:marg ...

  9. ACM 兄弟郊游问题

    兄弟郊游问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 兄弟俩骑车郊游,弟弟先出发,每分钟X米,M分钟后,哥哥带一条狗出发.以每分钟Y米的速度去追弟弟,而狗则以 ...

  10. 【JAVA】通过公式字符串表达式计算值,网上的一种方法

    public class Test {    public static void main(String[] args) {     SimpleCalculator s=new SimpleCal ...