惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
L
LINUX DO - 热门话题
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threat Research - Cisco Blogs
AI
AI
B
Blog RSS Feed
S
Schneier on Security
雷峰网
雷峰网
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Cloudbric
Cloudbric
L
LINUX DO - 最新话题
罗磊的独立博客
有赞技术团队
有赞技术团队
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
The Hacker News
The Hacker News
博客园 - Franky
Attack and Defense Labs
Attack and Defense Labs
The Cloudflare Blog
Webroot Blog
Webroot Blog
Last Week in AI
Last Week in AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 叶小钗
美团技术团队
L
Lohrmann on Cybersecurity
T
The Blog of Author Tim Ferriss
The Last Watchdog
The Last Watchdog
T
Troy Hunt's Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
Know Your Adversary
Know Your Adversary
O
OpenAI News
博客园 - 【当耐特】
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cybersecurity and Infrastructure Security Agency CISA
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
PCI Perspectives
PCI Perspectives
H
Heimdal Security Blog
I
InfoQ
GbyAI
GbyAI
T
Threatpost
C
Cisco Blogs

星辰日记

临时邮箱:开发者的隐私工具实践笔记 为 QuMagie 备份的照片添加 Exif 信息 Riverpod - flutter 状态管理的应用 夜景随拍 大疆 Mini 4K 初体验 5月12日 随笔 你好 2024 HHKB 使用体验 历经59天, 终于拿到软著 渺软公益CDN - 又一个静态资源加速站 你好 2023 记一次 RAID 硬盘离线 大一 碎语 试用 Google CA 的 SSL 证书 Waline 邮件异步推送 Magic Trackpad 使用体验 Centos 编译安装 php81 Redis 统计实时在线人数 Centos 7 升级 Glibc-2.28
Nginx 重写 Query 参数
xcsoft · 2022-05-25 · via 星辰日记

由于旧版项目, 依旧使用php-fpm模式提供api服务, 采用 类似 /api.php?m=account&act=login类似这种方式进行控制器分类.

目前的话 打算更换为其他框架, 使用路由来分配控制器.

由于前端及软件迁移成本较高, 就想着是否可以通过Nginx的伪静态来重写.

于是一开始尝试使用

1
2
3
4
location / {
proxy_pass https://127.0.0.1:8787;
rewrite ^api.php\?m=(.*)&act=(.*) /$1/$2 break;
}

直接对其进行重写, 但测试后发现并为达到预期的效果, 服务端接收到的 依旧只有/api.php

貌似并未被nginx匹配到, 查询过后发现 这样貌似是匹配不到路径的?

最终在查询过后, 发现可以通过 query_string 来对其进行匹配

1
2
3
4
5
6
7
8
9
10
11
12
location /api.php {
proxy_pass http://127.0.0.1:8787;
if ( $query_string ~ ^m=(.*)&act=(.*)) {
set $a $1;
set $b $2;
rewrite ^/(.*)$ /$a/$b break;
}
}

location / {
proxy_pass http://127.0.0.1:8787;
}

修改配置文件后, 再次对其进行测试, 成功将/api.php?m=account&act=login重写为/account/login