宝塔面板lnmp架构,tp6框架网站伪静态

伪静态A

location / {

index index.html index.htm index.php;

try_files uri uri/ /index.php?s=uri\&args;

if (!-e $request_filename) {

rewrite ^/(.*) /index.php?s=/1 last;

}

client_max_body_size 5048m;

add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';

add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization, ut, Accept, type';

if ($request_method = 'OPTIONS') {

return 204;

}

}

location ~ \.php$ {

fastcgi_pass unix:/tmp/php-cgi-74.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME document_rootfastcgi_script_name;

include fastcgi_params;

fastcgi_param PATH_INFO $fastcgi_path_info;

}

location /web {

try_files uri uri/ /web/index.html;

add_header Cache-Control 'no-cache, no-store, must-revalidate';

expires 0;

}

伪静态B

location / {

index index.html index.htm index.php;

#try_files uri uri/ /web/index.html;

if (!-e $request_filename){

rewrite ^(.*) /index.php?s=1;

}

client_max_body_size 5048m;

add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';

add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization, ut, Accept, type';

if ($request_method = 'OPTIONS') {

return 204;

}

}

location /web{

try_files uri uri/ /web/index.html;

add_header Cache-Control 'no-cache, no-store, must-revalidate';

expires 0;

}

对比项 能工作的配置(配置A) 不能工作的配置(配置B) 差异影响
核心方法 try_files $uri $uri/ /index.php?s=$uri&$args; if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1; } try_files更稳定,是nginx原生指令;rewrite依赖正则匹配
URL路径处理 $uri(规范化后的URI) $1(正则捕获的原始内容) $uri会自动解码、移除多余斜杠;$1保持原始状态
查询参数处理 &$args 明确保留原始查询参数 未明确处理查询参数 配置A能正确传递?key=value参数,配置B可能丢失
前导斜杠 自动包含($uri/开头) 可能丢失($1从正则起点开始) 关键差异 :配置A生成s=/path,配置B生成s=path
PHP location块 包含fastcgi_param PATH_INFO $fastcgi_path_info; 缺失PATH_INFO配置 影响pathinfo模式的路由解析
配置结构 使用try_files单一指令 使用if+rewrite组合 try_files更高效,避免if指令的潜在问题
错误处理 nginx内部处理文件不存在 依赖-e文件检查 try_files性能更好,语义更清晰

结论:

配置B的主要问题是缺少前导斜杠和可能丢失查询参数。使用$request_uri或确保添加前导斜杠即可修复。

复制代码
if (!-e $request_filename){
    rewrite ^/(.*)$ /index.php?s=/$1 last;
}
相关推荐
jwn9993 小时前
Laravel6.x核心特性全解析
开发语言·php·laravel
wuxinyan1234 小时前
Java面试题47:一文深入了解Nginx
java·nginx·面试题
小敬爱吃饭4 小时前
Ragflow Docker部署及问题解决方案(界面为Welcome to nginx,ragflow上传文件失败,Docker中的ragflow-cpu-1一直重启)
人工智能·python·nginx·docker·语言模型·容器·数据挖掘
星辰徐哥4 小时前
5G的行业应用:工业互联网、车联网、智慧医疗中的网络支撑
网络·5g·php
三道渊5 小时前
进程通信与网络协议
开发语言·数据库·php
流觞 无依5 小时前
DedeCMS plus/download.php SQL注入漏洞修复教程
sql·php
Freak嵌入式5 小时前
MicroPython LVGL基础知识和概念:显示与多屏管理
开发语言·python·github·php·gui·lvgl·micropython
Freak嵌入式6 小时前
MicroPython LVGL基础知识和概念:时序与动态效果
开发语言·python·github·php·gui·lvgl·micropython
龙卷风卷云8 小时前
【BUG】Nginx使用upstream后端接口报 400
运维·nginx·bug
fengci.9 小时前
php反序列化(复习)(第三章)
android·开发语言·学习·php