ThinkPHP3.2.3 Nginx 下 URL_MODEL 的配置
2024-09-16 23:37:07
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 配置文件
最新文章
- [C#] 剖析 AssemblyInfo.cs - 了解常用的特性 Attribute
- Torch学习笔记1--Torch简介
- [javascript svg fill stroke stroke-width x1 y1 x2 y2 line stroke-opacity fill-opacity 属性讲解] svg fill stroke stroke-width stroke-opacity fill-opacity line绘制线条属性讲解
- Docker入门教程(七)Docker API
- ng-repeat指令使用详解
- 【Unity3D游戏开发】之全局管理类的几种方式 (十六)
- Discuz DB层跨库映射关系表名前缀BUG修复后产生的新bug
- 20145215《Java程序设计》第3周学习总结
- Nginx 配置 Basic 认证
- Flume NG之Interceptor简介
- UVALive 7461	Separating Pebbles (计算几何)
- Android学习之路——简易版微信为例(二)
- Windows7下32位IE异常不能打开解决方法
- 【深度学习笔记】(二)基于MNIST数据集的神经网络实验
- 将html table 转成 excel
- DRUID连接池配置详情
- 网络流24题 ——运输问题 luogu 4015
- Go Web:RESTful web service示例
- PDO访问Mysql数据库
- shell 命令使用笔记
热门文章
- [工作中的设计模式]适配器模式adapter
- js-面向对象的程序设计,函数表达式
- js-变量、作用域和内存问题,引用类型
- poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举
- 怎么提高Jquery性能
- Regionals 2012 :: Chengdu
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
- 显式Intent和隐式Intent
- Issues I encountered when building Windows Store apps on a new laptop
- BZOJ 1001 题解