在Nginx上部署ThinkPHP,解决Pathinfo有关问题
在Nginx上部署ThinkPHP,解决Pathinfo问题
在Nginx上部署ThinkPHP,解决Pathinfo问题
其实,要解决nginx不支持pathinfo的问题,有两个解决思路,一是不使用pathinfo模式,二是修改nginx的配置文件,使它支持pathinfo。为了使问题简单化,我选择了第一种方式,因为就第二种方式,我查了很多资料,发现大家的方法不尽相同,有的还差别很大,容易造成误导,所以我选择从简出发,选择普通模式,虽然有一定的风险。当把index.php对应的前台代码修改完毕之后,发现前台基本正常,可是后台仍然出现重定向的问题。折腾了半天之后,我才想到看一下日志文件,原来是编辑器的问题,看来日志文件真的很重要,以前一直不重视。在config.php文件的第一行出现了输出,

在sublime下,一般会为UTF-8文件添加BOM头,这个BOM头在window下通常是看不见的,可以通过其他的编辑器查看到,Linux下也可以直接看到,通常显示出来是一个乱码字符,把这个字符删除即可,或者简单一点,直接在第一行回车,再删除就可以了。到这里,后台基本可以访问了。
有几个小问题需要说明一下(参考:http://www.lai18.com/content/368727.html)
1.在登录的时候,我是通过外部js文件发送Ajax请求进行验证的,在js与ThinkPHP模块函数通信遇到了点问题,一直不知道正确的路径该怎么写,也没有查到相关资料,只能各种试,好在找到了解决办法,通过直接带上入口文件名的方式,代码如下
1 |
|
当然,此为普通模式下的访问方式,如果是pathinfo的话,只需要把红色部分如下修改即可
1 |
|
2.下载文件的时候,总是莫名多出许多html的东西,原因是缓冲区没有清空,可以通过以下代码进行修改,不过这种方式实际上是下载的仍然是html格式的文件,只不过改了一下后缀名为xls而已,因而用excel打开的时候会提示格式问题,忽略即可。同时需要注意使用 icov()函数转换编码,因为xls默认编码格式并非utf-8.
1 |
|
3.在删除文件时会遇到路径问题,因为项目中使用的较多的是相对路径,即相对入口文件而言,但是删除文件则需要使用绝对路径,我并没有找到合适的解决方法,只好用了比较保守的方式,代码如下
1 |
|
4.在配置nginx和php方面,我使用了fastCGI的方式,将如下代码保存为cmd文件,直接点击运行就可以了
"F:\php\php-cgi.exe" -b 127.0.0.1:9000 -c "F:\php\php.ini" //后面是php文件的路径
然后在nginx的配置文件里加上几句话
1 |
|
延伸阅读
《PHP框架ThinkPHP学习》系列技术文章整理收藏
1Thinkphp实现MySQL读写分离操作示例
2使用ThinkPHP+Uploadify实现图片上传功能
3ThinkPHP调用百度翻译类实现在线翻译
4Thinkphp使用mongodb数据库实现多条件查询方法
5ThinkPHP实现多数据库连接的解决方法
6改写ThinkPHP的U方法使其路由下分页正常
7ThinkPHP实现将SESSION存入MYSQL的方法
8ThinkPHP连接数据库及主从数据库的设置教程
9ThinkPHP中pathinfo的访问模式、路径访问模式及URL重写总结
10ThinkPHP基于PHPExcel导入Excel文件的方法
11thinkphp获取栏目和文章当前位置的方法
12ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法
13ThinkPHP无限级分类原理实现留言与回复功能实例
14ThinkPHP在新浪SAE平台的部署实例
15ThinkPHP控制器间实现相互调用的方法
16ThinkPHP实现带验证码的文件上传功能实例
17ThinkPHP写数组插入与获取最新插入数据ID实例
18ThinkPHP水印功能实现修复PNG透明水印并增加JPEG图片质量可调整
19thinkphp使用literal防止模板标签被解析的方法
20ThinkPHP中RBAC类的四种用法分析
21ThinkPHP中__initialize()和类的构造函数__construct()用法分析
22ThinkPHP自动完成中使用函数与回调方法实例
23ThinkPHP实现动态包含文件的方法
24thinkphp实现发送邮件密码找回功能实例
25ThinkPHP实现支付宝接口功能实例
26Thinkphp搜索时首页分页和搜索页保持条件分页的方法
27ThinkPHP入口文件设置及相关注意事项分析
28ThinkPHP模版引擎之变量输出详解
29thinkphp实现上一篇与下一篇的方法
30ThinkPHP中url隐藏入口文件后接收alipay传值的方法
31ThinkPHP打开验证码页面显示乱码的解决方法
32ThinkPHP中使用ajax接收json数据的方法
33ThinkPHP内置jsonRPC的缺陷分析
34thinkphp3.0输出重复两次的解决方法
35thinkPHP实现表单自动验证
36Thinkphp中的curd应用实用要点
37浅谈thinkphp的实例化模型
38ThinkPHP 404页面的设置方法
39THINKPHP内容分页代码分享
40在Nginx上部署ThinkPHP项目教程
41浅析THINKPHP的addAll支持的最大数据量
42ThinkPHP提示错误Fatal error: Allowed memory size的解决方法
43ThinkPHP3.2.2的插件控制器功能
44ThinkPHP3.2.3数据库设置新特性
45ThinkPHP 3.2 版本升级了哪些内容
46thinkPHP学习笔记之安装配置篇
47Thinkphp调用Image类生成缩略图的方法
48解决ThinkPHP关闭调试模式时报错的问题汇总
49ThinkPHP文件缓存类代码分享
版权声明:本文为博主原创文章,未经博主允许不得转载。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

RPC service based on ThinkPHP6 and Swoole implements file transfer function Introduction: With the development of the Internet, file transfer has become more and more important in our daily work. In order to improve the efficiency and security of file transfer, this article will introduce the specific implementation method of the RPC service based on ThinkPHP6 and Swoole to implement the file transfer function. We will use ThinkPHP6 as the web framework and utilize Swoole's RPC function to achieve cross-server file transfer. 1. Environmental standard
