您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

ThinkPHP 的 nginx 配置踩坑

2025/6/14 0:42:25发布29次查看
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 配置踩坑的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product