THINKPHP 的 NGINX 配置踩坑
今天在用一个以 tp 为基础的快速开发框架时遇到一些问题:
nginx 报错截图
为了方便说明进行手动换行
// 处理时重写或内部重定向循环 2019/11/11 11:16:06 [error] 15164#15432: *1 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index/user/index.html", client: 127.0.0.1, server: xxxxx, request: "GET /index/user/index.html HTTP/1.1", host: "xxxxx", referrer: "xxxxx"
错误配置
参考 larvael 配置
server { . . . location / { try_files $uri $uri/ /index.php?$query_string; } . . . location ~ \.php$ { fastcgi_pass127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } . . . }
发现所有路径都一样,都是首页效果
初步判断 nginx 重写规则有问题
# 路径 / 开头之后都走这个匹配 # 如 /index /index/user location / { # $uri 本地有就返回,或者$uri/ 本地有目录就返回,或者走后面的重写 # 本地是指在网站根目录下,如 当 $uri=index 就是看根目录下面有 index 文件或者 index/ 目录 try_files $uri $uri/ /index.php?$query_string; }
开始报错
解决问题
网上查询后 tp5 的配置应为
location / { try_files $uri $uri/ /index.php$uri; }
改后,发现问题没解决;对比配置发现
# location ~ \.php$ 改成 location ~ \.php(.*)$ location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }
解决,完整配置
server { listen 80; server_name xxxxxxx ; root www; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; charset utf-8; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php$uri; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } }
推荐学习:thinkphp教程
以上是ThinkPHP 的 nginx 配置踩坑的详细内容。更多信息请关注PHP中文网其他相关文章!
声明
本文转载于:learnku。如有侵权,请联系admin@php.cn删除

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前ByDDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前ByDDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前ByDDD
<🎜>:死铁路 - 如何完成所有挑战
4 周前ByDDD
Atomfall指南:项目位置,任务指南和技巧
4 周前ByDDD

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)